﻿using FreeADO.DBUtility;
using System;
using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;
using System.Linq;
using System.Reflection;
using System.Web;

namespace ErpHelper.V995
{
    public class ErpHelper
    {


        /// <summary>
        /// 获取员工的DtypeId和StypeId
        /// </summary>
        /// <param name="EtypeId"></param>
        /// <returns></returns>
        public static DtypeIdAndStypeIdModel GetDtypeIdAndStypeIdByEtypeId(string EtypeId)
        {
            var result = new DtypeIdAndStypeIdModel();
            var sql = "select DtypeId,StypeId from employee where deleted = 0 and typeId = '" + EtypeId + "'";
            var List = ModelConvertHelper<DtypeIdAndStypeIdModel>.GetListForSql(sql).ToList();
            if (List != null && List.Count > 0)
            {
                result = List[0];
            }
            return result;

        }

        /// <summary>
        /// 获取单据编号
        /// </summary>
        /// <param name="BillType"></param>
        /// <param name="BillDate"></param>
        /// <param name="BillFlag">需要调查下ERP中的值</param>
        /// <param name="StypeID">先试用00001</param>
        /// <returns></returns>
        public static string GetBillCode(DbHelperSQLP db, int BillType, string BillDate, string BillFlag, string StypeID)
        {
            return db.GetSingle(@"
declare @p1 nvarchar(4000)
set @p1=N''
exec Gp_GetBillCode @BCode=@p1 output,@BType=" + BillType + @",@Month=N'" + Convert.ToDateTime(BillDate).Month + "',@Day=N'" + Convert.ToDateTime(BillDate).Day + "',@BillDate=N'" + BillDate + @"',@BillFlag=N'" + BillFlag + "',@STypeid=N'" + StypeID + @"',@BillNumberId=N'-1'
select @p1
").ToString();
        }
        /// <summary>
        /// 保存单据编号
        /// </summary>
        /// <param name="BillNumberID"></param>
        /// <param name="BillDate"></param>
        /// <param name="BillCode"></param>
        /// <param name="BillType">34是买进，17是调拨，6是退货</param>
        public static void SaveBillCode(DbHelperSQLP db, int BillNumberID, string BillDate, string BillCode, int BillType)
        {
            //exec GP_SaveBillCode_Seed @intBillNumberID=4,@dBillDate='2023-07-28 00:00:00',@intBillType=34,@strBillCode=N'JK-T-2023-07-28-0002'
            var result = db.GetSingle(@"exec GP_SaveBillCode_Seed @intBillNumberID=" + BillNumberID + ",@dBillDate='" + BillDate + "',@intBillType=" + BillType + ",@strBillCode='" + BillCode + @"'");
        }
        public static int InsertOrderIndex(OrderIndexParam m)
        {
            SqlParameter[] parameters = {
                 new SqlParameter("@BtypeId",SqlDbType.VarChar,50),
                 new SqlParameter("@EtypeId",SqlDbType.VarChar,50),
                 new SqlParameter("@KtypeId",SqlDbType.VarChar,50),
                 new SqlParameter("@BillDate",SqlDbType.DateTime),
                 new SqlParameter("@BillCode",SqlDbType.VarChar,200),
                 new SqlParameter("@BillType",SqlDbType.Int),
                 new SqlParameter("@TotalMoney",SqlDbType.Decimal),
                 new SqlParameter("@TotalQty",SqlDbType.Decimal),
                 new SqlParameter("@Period",SqlDbType.Int),
                 new SqlParameter("@Checked",SqlDbType.Bit),
                 new SqlParameter("@RedWord",SqlDbType.Bit),
                 new SqlParameter("@Explain",SqlDbType.VarChar,250),
                 new SqlParameter("@ReachDate",SqlDbType.DateTime),
                 new SqlParameter("@Comment",SqlDbType.VarChar,250),
                 new SqlParameter("@Checke",SqlDbType.VarChar,50),
                 new SqlParameter("@Tax",SqlDbType.Decimal),
                 new SqlParameter("@BillStatus",SqlDbType.Int),
                 new SqlParameter("@etypeid2",SqlDbType.VarChar,50),
                 new SqlParameter("@WayMode",SqlDbType.VarChar,50),
                 new SqlParameter("@WayBillCode",SqlDbType.VarChar,50),
                 new SqlParameter("@GoodsNumber",SqlDbType.VarChar,20),
                 new SqlParameter("@PackWay",SqlDbType.VarChar,20),
                 new SqlParameter("@TEL",SqlDbType.VarChar,100),
                 new SqlParameter("@DtypeId",SqlDbType.VarChar,50),
                 new SqlParameter("@STypeID",SqlDbType.VarChar,50),
                 new SqlParameter("@CustomerTotal",SqlDbType.Decimal),
                 new SqlParameter("@NCustomerTotal",SqlDbType.Decimal),
                 new SqlParameter("@NTotalMoney",SqlDbType.Decimal),
                 new SqlParameter("@CId",SqlDbType.Int),
                 new SqlParameter("@Rate",SqlDbType.Decimal),
                 new SqlParameter("@BillProperty",SqlDbType.Int),
                 new SqlParameter("@dealbtypeid",SqlDbType.VarChar,50),
                 new SqlParameter("@isyapi",SqlDbType.Int),
                 new SqlParameter("@yapiorderid",SqlDbType.VarChar,20),
                 new SqlParameter("@Discount",SqlDbType.Decimal),
                 new SqlParameter("@ATypeID",SqlDbType.VarChar,50),
                 new SqlParameter("@TotalInMoney",SqlDbType.Decimal),
                 new SqlParameter("@NTotalInMoney",SqlDbType.Decimal),
                 new SqlParameter("@VipCardID",SqlDbType.Int),
                 new SqlParameter("@projectid",SqlDbType.Int),
                 new SqlParameter("@ReturnValue",SqlDbType.VarChar,100) };
            parameters[0].Value = m.BtypeId;
            parameters[1].Value = m.EtypeId;
            parameters[2].Value = m.KtypeId;
            parameters[3].Value = m.BillDate;
            parameters[4].Value = m.BillCode;
            parameters[5].Value = m.BillType;
            parameters[6].Value = m.TotalMoney;
            parameters[7].Value = m.TotalQty;
            parameters[8].Value = m.Period;
            parameters[9].Value = m.Checked;
            parameters[10].Value = m.RedWord;
            parameters[11].Value = m.Explain;
            parameters[12].Value = m.ReachDate;
            parameters[13].Value = m.Comment;
            parameters[14].Value = m.Checke;
            parameters[15].Value = m.Tax;
            parameters[16].Value = m.BillStatus;
            parameters[17].Value = m.etypeid2;
            parameters[18].Value = m.WayMode;
            parameters[19].Value = m.WayBillCode;
            parameters[20].Value = m.GoodsNumber;
            parameters[21].Value = m.PackWay;
            parameters[22].Value = m.TEL;
            parameters[23].Value = m.DtypeId;
            parameters[24].Value = m.STypeID;
            parameters[25].Value = m.CustomerTotal;
            parameters[26].Value = m.NCustomerTotal;
            parameters[27].Value = m.NTotalMoney;
            parameters[28].Value = m.CId;
            parameters[29].Value = m.Rate;
            parameters[30].Value = m.BillProperty;
            parameters[31].Value = m.dealbtypeid;
            parameters[32].Value = m.isyapi;
            parameters[33].Value = m.yapiorderid;
            parameters[34].Value = m.Discount;
            parameters[35].Value = m.ATypeID;
            // parameters[36].Value = m.TotalInMoney;
            parameters[37].Value = m.NTotalInMoney;
            parameters[38].Value = m.VipCardID;
            parameters[39].Value = m.ProjectID;
            parameters[40].Direction = ParameterDirection.ReturnValue;
            DataSet ds = DbHelperSQL.RunProcedure("Gp_InsertOrderIndex", parameters, "aaa", 3000);
            return Convert.ToInt32(parameters[40].Value);
        }
        public static void InsertOrderBill(int intFlag, int billNumberId, int billType, List<OrderBillModel> l)
        {
            SqlParameter[] paras ={
                                           new SqlParameter("@intFlag", SqlDbType.Int),
                                           new SqlParameter("@billNumberId", SqlDbType.Int),
                                           new SqlParameter("@billType", SqlDbType.Int),
                                           new SqlParameter("@tb", Newtonsoft.Json.JsonConvert.DeserializeObject<DataTable>(Newtonsoft.Json.JsonConvert.SerializeObject(l))),
                                           new SqlParameter("@ReturnValue", SqlDbType.Int)
            };
            paras[0].Value = intFlag;
            paras[1].Value = billNumberId;
            paras[2].Value = billType;
            paras[3].SqlDbType = SqlDbType.Structured;
            paras[3].TypeName = "dbo.TbType_Order";
            paras[4].Direction = ParameterDirection.ReturnValue;

            DataSet ds = DbHelperSQL.RunProcedure("Gp_UpdateOrderBillDT", paras, "aaa", 3000);
        }
        public static int InsertBillIndex(DbHelperSQLP db, BillIndexParam m)
        {
            SqlParameter[] parameters = {
                        new SqlParameter("@BillDate",SqlDbType.DateTime),                                              //0
                        new SqlParameter("@BillCode",SqlDbType.VarChar,200),                                           //1
                        new SqlParameter("@BillType",SqlDbType.Decimal),                                               //2
                        new SqlParameter("@Comment",SqlDbType.VarChar,4000),                                           //3
                        new SqlParameter("@AtypeId",SqlDbType.VarChar,50),                                             //4
                        new SqlParameter("@PtypeId",SqlDbType.VarChar,50),                                             //5
                        new SqlParameter("@BtypeId",SqlDbType.VarChar,50),                                             //6
                        new SqlParameter("@EtypeId",SqlDbType.VarChar,50),                                             //7
                        new SqlParameter("@KtypeId",SqlDbType.VarChar,50),                                             //8
                        new SqlParameter("@KtypeId2",SqlDbType.VarChar,50) ,                                           //9
                        new SqlParameter("@IfCheck",SqlDbType.Char),                                                   //10
                        new SqlParameter("@CheckE",SqlDbType.VarChar,50) ,                                             //11
                        new SqlParameter("@TotalMoney",SqlDbType.Decimal),                                             //12
                        new SqlParameter("@TotalQty",SqlDbType.Decimal),                                               //13
                        new SqlParameter("@TotalInMoney",SqlDbType.Decimal),                                           //14
                        new SqlParameter("@Tax",SqlDbType.Decimal),                                                    //15
                        new SqlParameter("@szPeriod",SqlDbType.SmallInt),                                              //16
                        new SqlParameter("@Explain",SqlDbType.VarChar,4000) ,                                          //17
                        new SqlParameter("@Draft",SqlDbType.Bit),                                                      //18
                        new SqlParameter("@RedWord",SqlDbType.Bit),                                                    //19
                        new SqlParameter("@OrderId",SqlDbType.Decimal),                                                //20
                        new SqlParameter("@WayBillCode",SqlDbType.VarChar,50) ,                                        //21
                        new SqlParameter("@Goodsnumber",SqlDbType.VarChar,20),                                         //22
                        new SqlParameter("@PackWay",SqlDbType.VarChar,20),                                             //23
                        new SqlParameter("@Tel",SqlDbType.VarChar,100),                                                //24
                        new SqlParameter("@preferencemoney",SqlDbType.Decimal),                                        //25
                        new SqlParameter("@AlertDay",SqlDbType.Int),                                                   //26
                        new SqlParameter("@Assessor",SqlDbType.VarChar,50),                                            //27
                        new SqlParameter("@IfAudit",SqlDbType.Char),                                                   //28
                        new SqlParameter("@Audit_explain",SqlDbType.VarChar,256),                                      //29
                        new SqlParameter("@DtypeId",SqlDbType.VarChar,50),                                             //30
                        new SqlParameter("@VipCardID",SqlDbType.Int),                                                  //31
                        new SqlParameter("@KTypeID3",SqlDbType.VarChar,50),                                            //32
                        new SqlParameter("@LinkMan",SqlDbType.VarChar,256),                                            //33
                        new SqlParameter("@LinkTel",SqlDbType.VarChar,256),                                            //34
                        new SqlParameter("@LinkAddr",SqlDbType.VarChar,256),                                           //35
                        new SqlParameter("@wxManID",SqlDbType.VarChar,50),                                             //36
                        new SqlParameter("@JieJianBillNumberID",SqlDbType.VarChar,200),                                //37
                        new SqlParameter("@JieJianID",SqlDbType.VarChar,200),                                          //38
                        new SqlParameter("@BaoXiuBillNumberID",SqlDbType.VarChar,200),                                 //39
                        new SqlParameter("@BaoXiuID",SqlDbType.VarChar,200),                                           //40
                        new SqlParameter("@BuyDate",SqlDbType.VarChar,200),                                            //41
                        new SqlParameter("@Serial",SqlDbType.VarChar,200),                                             //42
                        new SqlParameter("@wxTotal",SqlDbType.Decimal),                                                //43
                        new SqlParameter("@ErrDes",SqlDbType.VarChar,3000),                                            //44
                        new SqlParameter("@ifHideJieJian",SqlDbType.Int),                                              //45
                        new SqlParameter("@ifWX",SqlDbType.Int),                                                       //46
                        new SqlParameter("@IfBargainOn",SqlDbType.Int),                                                //47
                        new SqlParameter("@STypeID",SqlDbType.VarChar,50),                                             //48
                        new SqlParameter("@FromBillNumberID",SqlDbType.Decimal),                                       //49
                        new SqlParameter("@CostSale",SqlDbType.Bit),                                                   //50
                        new SqlParameter("@completedate",SqlDbType.DateTime),                                          //51
                        new SqlParameter("@billstate",SqlDbType.Int),                                                  //52
                        new SqlParameter("@ifmulaccount",SqlDbType.Int),                                               //53
                        new SqlParameter("@vipczmoney",SqlDbType.Decimal),                                             //54
                        new SqlParameter("@otherinouttype",SqlDbType.Int),                                             //55
                        new SqlParameter("@czbeforetimes",SqlDbType.Decimal),                                          //56
                        new SqlParameter("@PosBillType",SqlDbType.Int),                                                //57
                        new SqlParameter("@TransportId",SqlDbType.VarChar,10) ,                                        //58
                        new SqlParameter("@IsFreightMoney",SqlDbType.Int),                                             //59
                        new SqlParameter("@FreightAddr",SqlDbType.VarChar,300) ,                                       //60
                        new SqlParameter("@FreightPerson",SqlDbType.VarChar,100) ,                                     //61
                        new SqlParameter("@FreightTel",SqlDbType.VarChar,100) ,                                        //62
                        new SqlParameter("@ShareMode",SqlDbType.TinyInt),                                              //63
                        new SqlParameter("@uf1",SqlDbType.VarChar,200),                                                //64
                        new SqlParameter("@uf2",SqlDbType.VarChar,200),                                                //65
                        new SqlParameter("@uf3",SqlDbType.VarChar,200),                                                //66
                        new SqlParameter("@uf4",SqlDbType.VarChar,200),                                                //67
                        new SqlParameter("@uf5",SqlDbType.VarChar,200),                                                //68
                        new SqlParameter("@DEALBTYPEID",SqlDbType.VarChar,50),                                         //69
                        new SqlParameter("@cid",SqlDbType.Int),                                                        //70
                        new SqlParameter("@rate",SqlDbType.Decimal),                                                   //71
                        new SqlParameter("@ntotalmoney",SqlDbType.Money),                                              //72
                        new SqlParameter("@ntotalinmoney",SqlDbType.Money),                                            //73
                        new SqlParameter("@npreferencemoney",SqlDbType.Money),                                         //74
                        new SqlParameter("@nvipczmoney",SqlDbType.Money),                                              //75
                        new SqlParameter("@atypeid1",SqlDbType.VarChar,50),                                            //76
                        new SqlParameter("@billproperty",SqlDbType.Int),                                               //77
                        new SqlParameter("@ncompletetotal",SqlDbType.Decimal),                                         //78
                        new SqlParameter("@isini",SqlDbType.Bit),                                                      //79
                        new SqlParameter("@ATID",SqlDbType.Int),                                                       //80
                        new SqlParameter("@completetotal",SqlDbType.Decimal),                                          //81
                        new SqlParameter("@IfCargo",SqlDbType.Bit),                                                    //82
                        new SqlParameter("@IfInvoice",SqlDbType.Int),                                                  //83
                        new SqlParameter("@invoicemoney",SqlDbType.Decimal),                                           //84
                        new SqlParameter("@ninvoicemoney",SqlDbType.Decimal),                                          //85
                        new SqlParameter("@importtype",SqlDbType.TinyInt),                                             //86
                        new SqlParameter("@AssetBusinessTypeId",SqlDbType.Int),                                        //87
                        new SqlParameter("@promoruleid",SqlDbType.Int),                                                //88
                        new SqlParameter("@beforepromobillnumberid",SqlDbType.Int),                                    //89
                        new SqlParameter("@promotionmsg",SqlDbType.VarChar,500),                                       //90
                        new SqlParameter("@STypeID2",SqlDbType.VarChar,50),                                            //91
                        new SqlParameter("@ifconfirm",SqlDbType.Int),                                                  //92
                        new SqlParameter("@FeeDeductType",SqlDbType.Int),                                              //93
                        new SqlParameter("@TransferType",SqlDbType.Int),                                               //94
                        new SqlParameter("@isyapi",SqlDbType.Int),                                                     //95
                        new SqlParameter("@yapiorderid",SqlDbType.VarChar,20),                                         //96
                        new SqlParameter("@DeliveryAddress",SqlDbType.VarChar,256),                                    //97
                        new SqlParameter("@Discount",SqlDbType.Decimal),                                               //98
                        new SqlParameter("@AdpriceType",SqlDbType.Int),                                                //99
                        new SqlParameter("@checkSave",SqlDbType.VarChar,128),                                          //100
                        new SqlParameter("@chargeoffbtypeid",SqlDbType.VarChar,50),                                    //101
                        new SqlParameter("@chargeofftype",SqlDbType.Int),                                              //102
                        new SqlParameter("@chargeofftotal",SqlDbType.Decimal),                                         //103
                        new SqlParameter("@nchargeofftotal",SqlDbType.Decimal),                                        //104
                        new SqlParameter("@IsLend",SqlDbType.Int),                                                     //105
                        new SqlParameter("@WarehouseOutDay",SqlDbType.Int),                                            //106
                        new SqlParameter("@StockInDeadline",SqlDbType.Int),                                            //107
                        new SqlParameter("@IsNeedTransport",SqlDbType.Bit),                                            //108
                        new SqlParameter("@iscombinationstyle",SqlDbType.Int),                                         //109
                        new SqlParameter("@transporterid",SqlDbType.VarChar,50),                                       //110
                        new SqlParameter("@transporterfullname",SqlDbType.VarChar,200),                                //111
                        new SqlParameter("@shipperfullname",SqlDbType.VarChar,100),                                    //112
                        new SqlParameter("@shipperperson",SqlDbType.VarChar,100),                                      //113
                        new SqlParameter("@shippertel",SqlDbType.VarChar,100),                                         //114
                        new SqlParameter("@transportno",SqlDbType.VarChar,200),                                        //115
                        new SqlParameter("@totalfreight",SqlDbType.Decimal),                                           //116
                        new SqlParameter("@ntotalfreight",SqlDbType.Decimal),                                          //117
                        new SqlParameter("@PromonIds",SqlDbType.VarChar,1000),                                         //118
                        new SqlParameter("@isByBrandarType",SqlDbType.Int),                                            //119
                        new SqlParameter("@NewPosBill",SqlDbType.Int),                                                 //120
                        new SqlParameter("@PayOnTheSpot",SqlDbType.Int),                                               //121
                        new SqlParameter("@posid",SqlDbType.Int),                                                      //122
                        new SqlParameter("@allowinvoicing",SqlDbType.Int),                                             //123
                        new SqlParameter("@projectid",SqlDbType.VarChar,50),//      VARCHAR(50)='',     --工程项目ID   //124
                        new SqlParameter("@usePM    ",SqlDbType.Int),//  INT = 0,                                      //125
                        new SqlParameter("@yjbxrq   ",SqlDbType.DateTime),//  DATETIME = NULL     --借款单预计报销日期 //126
                        new SqlParameter("@ReturnValue",SqlDbType.Int)                                                 //127

            };
            parameters[0].Value = m.BillDate;
            parameters[1].Value = m.BillCode;
            parameters[2].Value = m.BillType;
            parameters[3].Value = m.Comment;
            parameters[4].Value = m.AtypeId;
            parameters[5].Value = m.PtypeId;
            parameters[6].Value = m.BtypeId;
            parameters[7].Value = m.EtypeId;
            parameters[8].Value = m.KtypeId;
            parameters[9].Value = m.KtypeId2;
            parameters[10].Value = m.IfCheck;
            parameters[11].Value = m.CheckE;
            parameters[12].Value = m.TotalMoney;
            parameters[13].Value = m.TotalQty;
            parameters[14].Value = m.TotalInMoney;
            parameters[15].Value = m.Tax;
            parameters[16].Value = m.szPeriod;
            parameters[17].Value = m.Explain;
            parameters[18].Value = m.Draft;
            parameters[19].Value = m.RedWord;
            parameters[20].Value = m.OrderId;
            parameters[21].Value = m.WayBillCode;
            parameters[22].Value = m.Goodsnumber;
            parameters[23].Value = m.PackWay;
            parameters[24].Value = m.Tel;
            parameters[25].Value = m.preferencemoney;
            parameters[26].Value = m.AlertDay;
            parameters[27].Value = m.Assessor;
            parameters[28].Value = m.IfAudit;
            parameters[29].Value = m.Audit_explain;
            parameters[30].Value = m.DtypeId;
            parameters[31].Value = m.VipCardID;
            parameters[32].Value = m.KTypeID3;
            parameters[33].Value = m.LinkMan;
            parameters[34].Value = m.LinkTel;
            parameters[35].Value = m.LinkAddr;
            parameters[36].Value = m.wxManID;
            parameters[37].Value = m.JieJianBillNumberID;
            parameters[38].Value = m.JieJianID;
            parameters[39].Value = m.BaoXiuBillNumberID;
            parameters[40].Value = m.BaoXiuID;
            parameters[41].Value = m.BuyDate;
            parameters[42].Value = m.Serial;
            parameters[43].Value = m.wxTotal;
            parameters[44].Value = m.ErrDes;
            parameters[45].Value = m.ifHideJieJian;
            parameters[46].Value = m.ifWX;
            parameters[47].Value = m.IfBargainOn;
            parameters[48].Value = m.STypeID;
            parameters[49].Value = m.FromBillNumberID;
            parameters[50].Value = m.CostSale;
            parameters[51].Value = m.completedate;
            parameters[52].Value = m.billstate;
            parameters[53].Value = m.ifmulaccount;
            parameters[54].Value = m.vipczmoney;
            parameters[55].Value = m.otherinouttype;
            parameters[56].Value = m.czbeforetimes;
            parameters[57].Value = m.PosBillType;
            parameters[58].Value = m.TransportId;
            parameters[59].Value = m.IsFreightMoney;
            parameters[60].Value = m.FreightAddr;
            parameters[61].Value = m.FreightPerson;
            parameters[62].Value = m.FreightTel;
            parameters[63].Value = m.ShareMode;
            parameters[64].Value = m.uf1;
            parameters[65].Value = m.uf2;
            parameters[66].Value = m.uf3;
            parameters[67].Value = m.uf4;
            parameters[68].Value = m.uf5;
            parameters[69].Value = m.DEALBTYPEID;
            parameters[70].Value = m.cid;
            parameters[71].Value = m.rate;
            parameters[72].Value = m.ntotalmoney;
            parameters[73].Value = m.ntotalinmoney;
            parameters[74].Value = m.npreferencemoney;
            parameters[75].Value = m.nvipczmoney;
            parameters[76].Value = m.atypeid1;
            parameters[77].Value = m.billproperty;
            parameters[78].Value = m.ncompletetotal;
            parameters[79].Value = m.isini;
            parameters[80].Value = m.ATID;
            parameters[81].Value = m.completetotal;
            parameters[82].Value = m.IfCargo;
            parameters[83].Value = m.IfInvoice;
            parameters[84].Value = m.invoicemoney;
            parameters[85].Value = m.ninvoicemoney;
            parameters[86].Value = m.importtype;
            parameters[87].Value = m.AssetBusinessTypeId;
            parameters[88].Value = m.promoruleid;
            parameters[89].Value = m.beforepromobillnumberid;
            parameters[90].Value = m.promotionmsg;
            parameters[91].Value = m.STypeID2;
            parameters[92].Value = m.ifconfirm;
            parameters[93].Value = m.FeeDeductType;
            parameters[94].Value = m.TransferType;
            parameters[95].Value = m.isyapi;
            parameters[96].Value = m.yapiorderid;
            parameters[97].Value = m.DeliveryAddress;
            parameters[98].Value = m.Discount;
            parameters[99].Value = m.AdpriceType;
            parameters[100].Value = m.checkSave;
            parameters[101].Value = m.chargeoffbtypeid;
            parameters[102].Value = m.chargeofftype;
            parameters[103].Value = m.chargeofftotal;
            parameters[104].Value = m.nchargeofftotal;
            parameters[105].Value = m.IsLend;
            parameters[106].Value = m.WarehouseOutDay;
            parameters[107].Value = m.StockInDeadline;
            parameters[108].Value = m.IsNeedTransport;
            parameters[109].Value = m.iscombinationstyle;
            parameters[110].Value = m.transporterid;
            parameters[111].Value = m.transporterfullname;
            parameters[112].Value = m.shipperfullname;
            parameters[113].Value = m.shipperperson;
            parameters[114].Value = m.shippertel;
            parameters[115].Value = m.transportno;
            parameters[116].Value = m.totalfreight;
            parameters[117].Value = m.ntotalfreight;
            parameters[118].Value = m.PromonIds;
            parameters[119].Value = m.isByBrandarType;
            parameters[120].Value = m.NewPosBill;
            parameters[121].Value = m.PayOnTheSpot;
            parameters[122].Value = m.posid;
            parameters[123].Value = m.allowinvoicing; //v3版不适用
            parameters[124].Value = m.ProjectID; //v3版不适用
            parameters[125].Value = m.UsePM; //v3版不适用
            parameters[126].Value = m.Yjbxrq; //v3版不适用
            parameters[127].Direction = ParameterDirection.ReturnValue;
            DataSet ds = db.RunProcedure("Gp_InsertBillIndex", parameters, "aaa", 3000);
            return Convert.ToInt32(parameters[127].Value);
        }
        public static void InsertSaleBill(DbHelperSQLP db, List<SaleBillModel> l)
        {
            SqlParameter[] paras ={
                                           new SqlParameter("@details", Newtonsoft.Json.JsonConvert.DeserializeObject<DataTable>(Newtonsoft.Json.JsonConvert.SerializeObject(l))),
                                           new SqlParameter("@ReturnValue", SqlDbType.Int)
            };
            paras[0].SqlDbType = SqlDbType.Structured;
            paras[0].TypeName = "dbo.TBType_Sale";
            paras[1].Direction = ParameterDirection.ReturnValue;

            DataSet ds = db.RunProcedure("Gp_InsertSaleBillDT", paras, "aaa", 3000);
        }
        public static void InsertSaleBackBill(List<SaleBackModel> l)
        {
            SqlParameter[] paras ={
                                           new SqlParameter("@details", Newtonsoft.Json.JsonConvert.DeserializeObject<DataTable>(Newtonsoft.Json.JsonConvert.SerializeObject(l))),
                                           new SqlParameter("@ReturnValue", SqlDbType.Int)
            };
            paras[0].SqlDbType = SqlDbType.Structured;
            paras[0].TypeName = "dbo.TBType_SaleBack";
            paras[1].Direction = ParameterDirection.ReturnValue;

            DataSet ds = DbHelperSQL.RunProcedure("Gp_InsertSaleBackBillDT", paras, "aaa", 3000);
        }
        public static void InsertRetailBill(List<RetailBillModel> l)
        {
            SqlParameter[] paras ={
                                           new SqlParameter("@details", Newtonsoft.Json.JsonConvert.DeserializeObject<DataTable>(Newtonsoft.Json.JsonConvert.SerializeObject(l))),
                                           new SqlParameter("@ReturnValue", SqlDbType.Int)
            };
            paras[0].SqlDbType = SqlDbType.Structured;
            paras[0].TypeName = "dbo.TBType_Retail";
            paras[1].Direction = ParameterDirection.ReturnValue;

            DataSet ds = DbHelperSQL.RunProcedure("Gp_InsertRetailBillDT", paras, "aaa", 3000);
        }
        public static void InsertRetailBackBill(List<RetailBackBillModel> l)
        {
            SqlParameter[] paras ={
                                           new SqlParameter("@details", Newtonsoft.Json.JsonConvert.DeserializeObject<DataTable>(Newtonsoft.Json.JsonConvert.SerializeObject(l))),
                                           new SqlParameter("@ReturnValue", SqlDbType.Int)
            };
            paras[0].SqlDbType = SqlDbType.Structured;
            paras[0].TypeName = "dbo.TBType_RetailBack";
            paras[1].Direction = ParameterDirection.ReturnValue;

            DataSet ds = DbHelperSQL.RunProcedure("Gp_InsertRetailBackBillDT", paras, "aaa", 3000);
        }
        public static void InsertGatheringBill(DbHelperSQLP db, List<GatheringBillModel> l)
        {
            SqlParameter[] paras ={
                                           new SqlParameter("@details", Newtonsoft.Json.JsonConvert.DeserializeObject<DataTable>(Newtonsoft.Json.JsonConvert.SerializeObject(l))),
                                           new SqlParameter("@ReturnValue", SqlDbType.Int)
            };
            paras[0].SqlDbType = SqlDbType.Structured;
            paras[0].TypeName = "dbo.TBType_Gathering";
            paras[1].Direction = ParameterDirection.ReturnValue;

            DataSet ds = db.RunProcedure("Gp_InsertGatheringBillDT", paras, "aaa", 3000);
        }
        public static void InsertMultAtype(DbHelperSQLP db, List<MultAtypeModel> l)
        {
            //exec Gp_InsertMultAtype @Total=9,@NTotalMoney=9,@BillNumberID=10005,@atypeid=2,@comment=NULL,@vipcardid=NULL,@tradeno=N'',@paytype=0,@billtype=11,@yhtype=-1,@couponcode=N'',@viptotal=0
            foreach (var item in l)
            {


                SqlParameter[] parameters = {
                        new SqlParameter("@BillNumberID",SqlDbType.Int),
                        new SqlParameter("@atypeid",SqlDbType.VarChar,200),
                        new SqlParameter("@comment",SqlDbType.VarChar,4000),
                        new SqlParameter("@Total",SqlDbType.Decimal),
                        new SqlParameter("@vipcardid",SqlDbType.Int),
                        new SqlParameter("@NTotalMoney",SqlDbType.Decimal),
                        new SqlParameter("@tradeno",SqlDbType.VarChar,200),
                        new SqlParameter("@paytype",SqlDbType.Int),
                        new SqlParameter("@billtype",SqlDbType.Int) ,
                        new SqlParameter("@yhType",SqlDbType.Int),
                        new SqlParameter("@CouponCode",SqlDbType.VarChar,4000) ,
                        new SqlParameter("@viptotal",SqlDbType.Decimal),
                        new SqlParameter("@atypecomment",SqlDbType.VarChar,500),
                        new SqlParameter("@ReturnValue",SqlDbType.Int)

            };
                parameters[0].Value = item.BillNumberID;
                parameters[1].Value = item.AtypeId;
                parameters[2].Value = item.Comment;
                parameters[3].Value = item.Total;
                parameters[4].Value = DBNull.Value;
                parameters[5].Value = item.NTotalMoney;
                parameters[6].Value = item.TradeNo;
                parameters[7].Value = item.PayType;
                parameters[8].Value = item.BillType;
                parameters[9].Value = item.yhType;
                parameters[10].Value = item.CouponCode;
                parameters[11].Value = item.viptotal;
                parameters[12].Value = item.atypecomment;
                parameters[13].Direction = ParameterDirection.ReturnValue;

                DataSet ds = db.RunProcedure("Gp_InsertMultAtype", parameters, "aaa", 3000);
            }
        }

        public static void InsertCompleteTotal_Draft(int MoneyBillID, int GoodsBillID, decimal Total, int GoodsBillType)
        {
            SqlParameter[] parm1 =
                            {
                                new SqlParameter("@intMoneyNumberId",MoneyBillID)
                            };
            DbHelperSQL.RunProcedure("GP_InsertCompleteTotal_DelDraft", parm1, "aaa", 30000);

            SqlParameter[] parm2 = {
                                new SqlParameter("@intGoodsNumberId",GoodsBillID),
                                new SqlParameter("@intMoneyNumberId",MoneyBillID),
                                new SqlParameter("@intGoodsDetailId","0"),
                                new SqlParameter("@decCompleteTotal",Total),
                                new SqlParameter("@decNCompleteTotal",Total),
                                new SqlParameter("@IsSelect","1"),
                                new SqlParameter("@GoodsBillType",GoodsBillType)
                            };
            DataSet b = DbHelperSQL.RunProcedure("GP_InsertCompleteTotal_Draft", parm2, "aaa", 30000);
        }
        public static void InsertCompleteTotal(int MoneyBillID, int GoodsBillID, decimal Total, int GoodsBillType)
        {


            SqlParameter[] parm2 = {
                                new SqlParameter("@intGoodsNumberId",GoodsBillID),
                                new SqlParameter("@intGoodsDetailId","0"),
                                new SqlParameter("@intMoneyNumberId",MoneyBillID),
                                new SqlParameter("@decCompleteTotal",Total),
                                new SqlParameter("@decNCompleteTotal",Total),
                                new SqlParameter("@IsGood","0"),
                                new SqlParameter("@GoodsBillType",GoodsBillType),
                            };
            DataSet b = DbHelperSQL.RunProcedure("GP_InsertCompleteTotal ", parm2, "aaa", 30000);
        }



        /// <summary>
        /// 采购入库调用 - 表：BuyBill
        /// </summary>
        /// <param name="l"></param>
        public static void InsertBuyBillDT(List<BuyBillModel> l)
        {
            SqlParameter[] paras ={
                                           new SqlParameter("@tb", Newtonsoft.Json.JsonConvert.DeserializeObject<DataTable>(Newtonsoft.Json.JsonConvert.SerializeObject(l))),
                                           new SqlParameter("@ReturnValue", SqlDbType.Int)
            };
            paras[0].SqlDbType = SqlDbType.Structured;
            paras[0].TypeName = "dbo.TbType_Buy";
            paras[1].Direction = ParameterDirection.ReturnValue;

            DataSet ds = DbHelperSQL.RunProcedure("GP_InsertBuyBillDT", paras, "aaa", 3000);
        }
        /// <summary>
        /// 采购退货调用 - 表：BuyBackBill
        /// </summary>
        /// <param name="l"></param>
        public static void InsertBuyBackBillDT(List<BuyBackBillModel> l)
        {
            SqlParameter[] paras ={
                                           new SqlParameter("@tb", Newtonsoft.Json.JsonConvert.DeserializeObject<DataTable>(Newtonsoft.Json.JsonConvert.SerializeObject(l))),
                                           new SqlParameter("@ReturnValue", SqlDbType.Int)
            };
            paras[0].SqlDbType = SqlDbType.Structured;
            paras[0].TypeName = "dbo.TbType_BuyBack";
            paras[1].Direction = ParameterDirection.ReturnValue;

            DataSet ds = DbHelperSQL.RunProcedure("GP_InsertBuyBackBillDT", paras, "aaa", 3000);
        }

        public static void InsertMoveBill(List<MoveBillParm> l)
        {
            SqlParameter[] paras ={
                                           new SqlParameter("@details", Newtonsoft.Json.JsonConvert.DeserializeObject<DataTable>(Newtonsoft.Json.JsonConvert.SerializeObject(l))),
                                           new SqlParameter("@ReturnValue", SqlDbType.Int)
            };
            paras[0].SqlDbType = SqlDbType.Structured;
            paras[0].TypeName = "dbo.TBType_MoveBill";
            paras[1].Direction = ParameterDirection.ReturnValue;

            DataSet ds = DbHelperSQL.RunProcedure("Gp_InsertMoveBillDT", paras, "aaa", 3000);
        }

        public static void InsertDissBill(List<DisassembleBillModel> l)
        {
            SqlParameter[] paras ={
                                           new SqlParameter("@details", Newtonsoft.Json.JsonConvert.DeserializeObject<DataTable>(Newtonsoft.Json.JsonConvert.SerializeObject(l))),
                                           new SqlParameter("@ReturnValue", SqlDbType.Int)
            };
            paras[0].SqlDbType = SqlDbType.Structured;
            paras[0].TypeName = "dbo.TBType_DissBill";
            paras[1].Direction = ParameterDirection.ReturnValue;

            DataSet ds = DbHelperSQL.RunProcedure("Gp_InsertDissBillDT", paras, "aaa", 3000);
        }




        /// <summary>
        /// 根据不同的成本算法返回一定数量在一定仓库的成本价
        /// </summary>
        /// <param name="chvPtypeId">商品Id</param>
        /// <param name="chvKtypeId">仓库Id</param>
        /// <param name="decQty">商品数量</param>
        /// <param name="intCosting">成本算法:0,移动加权平均;1,先进先出;2,后进先出</param>
        /// <returns></returns>
        public static decimal WebCalculateCostPrice(string chvPtypeId, string chvKtypeId, int decQty, string intCosting = "0", int BillType = -1, int BillNumberId = -1)
        {
            decimal result = 0;

            SqlParameter[] parmsyy = {
                                            new SqlParameter("@chvPtypeId", SqlDbType.VarChar,50),//商品Id
                                            new SqlParameter("@chvKtypeId",SqlDbType.VarChar,50),//仓库Id
                                            new SqlParameter("@decQty",SqlDbType.Decimal),//商品数量
                                            new SqlParameter("@intCosting",SqlDbType.Int),//成本算法:0,移动加权平均;1,先进先出;2,后进先出
                                            new SqlParameter("@BillType",SqlDbType.Int),//成本算法:0,移动加权平均;1,先进先出;2,后进先出
                                            new SqlParameter("@BillNumberId",SqlDbType.Int),//成本算法:0,移动加权平均;1,先进先出;2,后进先出
                                           };

            parmsyy[0].Value = chvPtypeId;
            parmsyy[1].Value = chvKtypeId;
            parmsyy[2].Value = decQty;
            parmsyy[3].Value = intCosting;
            parmsyy[4].Value = BillType;
            parmsyy[5].Value = BillNumberId;


            DataSet ds = DbHelperSQL.RunProcedure("Web_CalculateCostPrice", parmsyy, "aaa", 3000);
            if (ds.Tables[0] != null && ds.Tables[0].Rows != null && ds.Tables[0].Rows.Count > 0)
            {
                result = Convert.ToDecimal(ds.Tables[0].Rows[0][0]);
            }
            if (result == 0)
            {
                result = 1;//测试使用
            }
            return result;
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="BillNumberId"></param>
        /// <param name="Etypeid"></param>
        /// <param name="OpID">先试用00001</param>
        /// <param name="BillType">对比看</param>
        /// <returns></returns>
        public static Result<string> Auditing(int BillNumberId, string Etypeid, string OpID, int BillType)
        {
            Result<string> result = new Result<string>();
            result.Type = AjaxResultType.Success;
            result.Content = "成功";
            result.TotalRows = 0;
            result.Data = "";
            SqlParameter[] parmsyy = {
                                            new SqlParameter("@nBillID", SqlDbType.Int),//单号
                                            new SqlParameter("@szCheckMan",SqlDbType.VarChar,50),//制单人
                                            new SqlParameter("@chvOpID",SqlDbType.VarChar,50),//当前操作员
                                            new SqlParameter("@billtype",SqlDbType.Int),//单据类型
                                            new SqlParameter("@szPID",SqlDbType.VarChar,1000),
                                            new SqlParameter("@Ret",SqlDbType.Int),
                                            new SqlParameter("@VipCentInfo",SqlDbType.VarChar,200),//     VARCHAR(200) = '' OUTPUT,               --返回会员卡积分调整信息
                                            new SqlParameter("@AssetMsg",SqlDbType.VarChar,4000),//     VARCHAR(MAX)='' OUTPUT,
                                            new SqlParameter("@VipCardCode",SqlDbType.VarChar,200),//     VARCHAR(200)='' OUTPUT,
                                            new SqlParameter("@CommissionConfirm",SqlDbType.Int),//     INT=0,
                                            new SqlParameter("@strReturnBillCode",SqlDbType.VarChar,200),//     VARCHAR(200)='' OUT

            };

            parmsyy[0].Value = BillNumberId;
            parmsyy[1].Value = Etypeid;
            parmsyy[2].Value = OpID;
            parmsyy[3].Value = BillType;
            parmsyy[4].Value = "";
            parmsyy[5].Value = 0;
            parmsyy[6].Value = "";
            parmsyy[7].Value = "";
            parmsyy[8].Value = "";
            parmsyy[9].Value = 0;
            parmsyy[10].Value = "";
            parmsyy[4].Direction = ParameterDirection.Output;
            parmsyy[5].Direction = ParameterDirection.Output;
            parmsyy[6].Direction = ParameterDirection.Output;
            parmsyy[7].Direction = ParameterDirection.Output;
            parmsyy[8].Direction = ParameterDirection.Output;
            parmsyy[10].Direction = ParameterDirection.Output;

            //DbHelperSQL.RunProcedure("Gp_NewAuditing", parmsyy);
            DataSet ds = DbHelperSQL.RunProcedure("Gp_NewAuditing", parmsyy, "aaa", 3000);
            string pr = parmsyy[5].Value.ToString();

            if (pr == "0")
            {

            }
            else
            {
                string returnMessage = "";
                switch (int.Parse(pr))
                {
                    case -11:
                        returnMessage = "单据往来科目不存在，生成凭证失败！";
                        break;
                    case -13:
                        returnMessage = "单据已经生成过凭证，生成凭证失败！";
                        break;
                    case -210:
                        returnMessage = "不存在默认模板，生成凭证失败！";
                        break;
                    case -211:
                        returnMessage = "凭证写入出错，生成凭证失败！";
                        break;
                    case -212:
                        returnMessage = "单据往来科目获取失败，凭证生成失败!";
                        break;
                    case -213:
                        returnMessage = "模板中有会计科目外币核算与单据币种不符，生成凭证失败!";
                        break;
                    case -214:
                        returnMessage = "模板对应单据金额全部为0，无法生成凭证！\n如单据金额字段不是全部为0，请检查模板后重新生成！\n模板中存在项目的请同时检查项目管理是否配置项目对应科目。";
                        break;
                    case -216:
                        returnMessage = "辅助核算获取失败，生成凭证失败！";
                        break;
                    case -217:
                        returnMessage = "凭证不符合保存规则，生成凭证失败，请检查模板！";
                        break;
                    case -218:
                        returnMessage = "凭证字不存在，生成凭证失败！";
                        break;
                    case -219:
                        returnMessage = "每行凭证分录必有摘要，模板不符，生成凭证失败！";
                        break;
                    case -220:
                        returnMessage = "模板不存在，生成凭证失败！";
                        break;
                    case -221:
                        returnMessage = "生成凭证要求录入现金流量，自动生成失败！";
                        break;
                    case -222:
                        returnMessage = "生成凭证科目不全，请检查项目设置！";
                        break;
                    case -223:
                        returnMessage = "您使用的是试用版，凭证数据不能大于200";
                        break;
                    case -224:
                        returnMessage = "配置要求每行分录必有摘要，生成凭证时分录存在摘要为空\n生成失败，请检查凭证模板或单据中【说明】\\【摘要】是否为空";
                        break;
                    case -225:
                        returnMessage = "凭证分录第一行摘要为空，请检查凭证模板或单据中字段【说明】\\【摘要】是否为空";
                        break;
                    case -226:
                        returnMessage = "当前单据生成的会计凭证无对应会计期间，请先结帐到下一年度再生成";
                        break;
                    case -227:
                        returnMessage = "总账未开账，不能生成凭证";
                        break;
                    case -228:
                        returnMessage = "生成凭证中有科目被停用，无法生成凭证";
                        break;
                    case -229:
                        returnMessage = "单据非资金调拨单，无法处理相应业务";
                        break;
                    case -230:
                        returnMessage = "出纳当前期间与总账期间不一致，不能生成凭证";
                        break;
                }
                if (returnMessage != "")
                {
                    result.Type = AjaxResultType.Warning;
                    result.Content = returnMessage;
                }
                else
                {
                    result.Type = AjaxResultType.Error;
                    result.Content = "过账异常，错误代码：" + pr;
                }
            }
            return result;
        }


        /// <summary>
        /// 时间戳反转为时间，有很多中翻转方法，但是，请不要使用过字符串（string）进行操作，大家都知道字符串会很慢！
        /// </summary>
        /// <param name="TimeStamp">时间戳</param>
        /// <param name="AccurateToMilliseconds">是否精确到毫秒，默认是</param>
        /// <returns>返回一个日期时间</returns>
        public static DateTime GetTime(long TimeStamp, bool AccurateToMilliseconds = true)
        {
            System.DateTime startTime = TimeZone.CurrentTimeZone.ToLocalTime(new System.DateTime(1970, 1, 1)); // 当地时区
            if (AccurateToMilliseconds)
            {
                return startTime.AddTicks(TimeStamp * 10000);
            }
            else
            {
                return startTime.AddTicks(TimeStamp * 10000000);
            }
        }

        /// <summary>
        /// 复制草稿或生成单据处理草稿库存
        /// </summary>
        /// <param name="BillNumberID">单据编号</param>
        /// <param name="BillType">单据类型 ： 115为应收减少单（应收款减少单）</param>
        /// <param name="EffectFlag">+：保存草稿、自动生成单据正向影响库存，-：单据过账、删除草稿负向影响库存 ， 默认 "+"</param>
        public static void GPDealDraftQTY(DbHelperSQLP db, int BillNumberID, int BillType, string EffectFlag = "+")
        {
            var result = db.GetSingle(@"exec GP_Deal_DraftQTY @BillNumberID=" + BillNumberID + ",@BillType=" + BillType + ",@EffectFlag='" + EffectFlag + @"'");
        }
        /// <summary>
        /// 应收款减少单-写入明细表(表值)
        /// </summary>
        /// <param name="l"></param>
        public static void GpInsertAdDebtBillDT(DbHelperSQLP db, List<AdDebtBill> l)
        {
            SqlParameter[] paras ={
                                           new SqlParameter("@details", Newtonsoft.Json.JsonConvert.DeserializeObject<DataTable>(Newtonsoft.Json.JsonConvert.SerializeObject(l))),
                                           new SqlParameter("@ReturnValue", SqlDbType.Int)
            };
            paras[0].SqlDbType = SqlDbType.Structured;
            paras[0].TypeName = "dbo.TBType_AdDebt";
            paras[1].Direction = ParameterDirection.ReturnValue;

            DataSet ds = db.RunProcedure("GP_InsertAdDebtBillDT", paras, "aaa", 3000);
        }

        #region tong 客户信息 新增、修改。

        /// <summary>
        /// 写入btype
        /// </summary>
        /// <param name="UserCode"></param>
        /// <param name="fullName"></param>
        public static int InsertBtype(DbHelperSQLP db, string ParID, string userCode, string fullName, string TelAndAddress, string PostCode, DateTime CreateDate, string Tel1, string LinkMan1, int LinkSex1, DateTime LinkBirthDay1, string LinkTel1, string LinkMobile1, string LinkAddress1, string Sheng, string Shi, string Xian)
        {
            SqlParameter[] parameters ={
                new SqlParameter("@Parid",ParID),//父节点ID
                new SqlParameter("@DbName", "btype"),
                new SqlParameter("@UserCode", userCode),
                new SqlParameter("@FullName", fullName),
                new SqlParameter("@Name", ""),
                new SqlParameter("@Area", ""),
                new SqlParameter("@TelAndAddress", TelAndAddress),
                new SqlParameter("@PostCode", PostCode),
                new SqlParameter("@Person", ""),
                new SqlParameter("@TaxNumber", ""),
                new SqlParameter("@bankandacount", ""),
                new SqlParameter("@Artotal00", 0.0000000000),
                new SqlParameter("@Aptotal00", 0.0000000000),
                new SqlParameter("@Comment", ""),
                new SqlParameter("@Client", 1),
                new SqlParameter("@ARLimit", 0.0000000000),
                new SqlParameter("@ARLimitTime", 9999),
                new SqlParameter("@PaymentLTime", 9999),
                new SqlParameter("@Tel1", Tel1),
                new SqlParameter("@Tel2", ""),
                new SqlParameter("@Tel3", ""),
                new SqlParameter("@WWW", ""),
                new SqlParameter("@Email", ""),
                new SqlParameter("@Fax", ""),
                new SqlParameter("@Bank", ""),
                new SqlParameter("@BankName", ""),
                new SqlParameter("@LinkMan1", LinkMan1),
                new SqlParameter("@LinkSex1", LinkSex1),
                new SqlParameter("@LinkBirthDay1", LinkBirthDay1<new DateTime(1970,1,1)?Convert.ToDateTime(DateTime.Now.ToString("yyyy-MM-dd")):LinkBirthDay1),
                new SqlParameter("@LinkJob1", ""),
                new SqlParameter("@LinkCall1", ""),
                new SqlParameter("@LinkTel1", LinkTel1),
                new SqlParameter("@LinkMobile1", LinkMobile1),
                new SqlParameter("@LinkEMail1", ""),
                new SqlParameter("@LinkPost1", ""),
                new SqlParameter("@LinkAddress1", LinkAddress1),
                new SqlParameter("@LinkComment1", ""),
                new SqlParameter("@LinkMan2", ""),
                new SqlParameter("@LinkSex2", 1),
                new SqlParameter("@LinkBirthDay2", "1980-01-01 00:00:00"),
                new SqlParameter("@LinkJob2", ""),
                new SqlParameter("@LinkCall2", ""),
                new SqlParameter("@LinkTel2", ""),
                new SqlParameter("@LinkMobile2", ""),
                new SqlParameter("@LinkEMail2", ""),
                new SqlParameter("@LinkPost2", ""),
                new SqlParameter("@LinkAddress2", ""),
                new SqlParameter("@LinkComment2", ""),//
                new SqlParameter("@CreateDate", CreateDate),// datetime,
                new SqlParameter("@SaleZeKou", 0),//  NUMERIC(24, 10) ,
                new SqlParameter("@BuyZeKou", 0),//  NUMERIC(24, 10) ,
                new SqlParameter("@PyCode", db.GetSingle("select dbo.fun_getPY('"+fullName+"')").ToString()),//   VARCHAR(200),
                new SqlParameter("@Price", "0"),//    VARCHAR(50),
                new SqlParameter("@AreaTypeID", ""),// VARCHAR(50),
                new SqlParameter("@ifStype", 0),// INT=0,
                new SqlParameter("@etypeid", ""),//            VARCHAR(50)='',     --职员
                new SqlParameter("@buyprice", "0"),//           VARCHAR(50)='',     --适用进价
                new SqlParameter("@consignee", ""),//          VARCHAR(100)='',    --收货人
                new SqlParameter("@consigneetel", ""),//       VARCHAR(100)='',    --收货人电话
                new SqlParameter("@consigneeaddress", ""),//   VARCHAR(1000)='',   --收货人地址
                new SqlParameter("@valeditprice", false),// BIT,
                new SqlParameter("@denominatedid", ""),// VARCHAR(100),
                new SqlParameter("@backlimitday", 0),//   INT,                --退换货期限(天)
                new SqlParameter("@backpercent", 0),//    INT,                --换货比例(%)
                new SqlParameter("@cid", 0),//            INT,                --关联货币
                new SqlParameter("@pricetrackenable", 1),// INT=1,                --1.启用价格跟踪 0.不启用
                new SqlParameter("@cqdays", DBNull.Value),// INT=NULL, --超期提前预警
                new SqlParameter("@chkskmonthday", 0),// INT=0 , --启用收款月结日 checkbox
                new SqlParameter("@skmonthday", DBNull.Value),// INT=NULL, --启用收款月结日
                new SqlParameter("@chkfkmonthday", 0),// INT=0, --启用付款月结日 checkbox
                new SqlParameter("@fkmonthday", DBNull.Value),// INT=NULL, --启用付款月结日
                new SqlParameter("@dzdays", DBNull.Value),// INT=NULL, --每月对账日期
                new SqlParameter("@dzwarningdays", DBNull.Value),// INT=NULL, --对账日提前预警天数
                new SqlParameter("@ckarlimittime", DBNull.Value),// int=NULL, --收款期限
                new SqlParameter("@ckpaymentltime", DBNull.Value),// INT= NULL, --付款期限
                new SqlParameter("@fkcqdays", DBNull.Value),//        INT =NULL, --付款超期提前预警
                new SqlParameter("@fkdzdays", DBNull.Value),//  INT=NULL,--付款每月对账日期
                new SqlParameter("@fkdzwarningdays", DBNull.Value),// int=NULL,  --付款对账日提前预警
                new SqlParameter("@iscarrier", false),// BIT=0,
                new SqlParameter("@sheng", Sheng),//      VARCHAR(100) = '',      --省
                new SqlParameter("@shi", Shi),//        VARCHAR(100) = '',      --市
                new SqlParameter("@xian", Xian),//       VARCHAR(100) = '',      --县
                new SqlParameter("@blevel", ""),//     VARCHAR(100) = ''       --单位等级
	            new SqlParameter("@isusebrandartype", false),//   BIT=0,                  --是否启用品牌应收
                new SqlParameter("@skmonth", DBNull.Value),//   VARCHAR(10) = NULL,     --收款第几月
                new SqlParameter("@skday", DBNull.Value),//   VARCHAR(10) = NULL,     --收款第几日
                new SqlParameter("@skdzdayflag", "0"),//   VARCHAR(10) = '0',      --按对账日期计算收款期限
                new SqlParameter("@fkmonth", DBNull.Value),//   VARCHAR(10) = NULL,     --付款第几月
                new SqlParameter("@fkday", DBNull.Value),//   VARCHAR(10) = NULL,     --付款第几日
                new SqlParameter("@fkdzdayflag", "0"),//   VARCHAR(10) = '0',      --按对账日期计算付款期限
                new SqlParameter("@skcyjartime", "0"),//   VARCHAR(10) = '0',      --收款次月结
                new SqlParameter("@fkcyjaptime", "0"),//   VARCHAR(10) = '0',      --付款次月结
                new SqlParameter("@operatorid", "0"),//   VARCHAR(50) = '',       --当前操作员
                new SqlParameter("@shopbtypeid", 0),//   INT = 0,                --用户组ID
                new SqlParameter("@stypeid", ""),//   VARCHAR(50) = ''        --分支机构ID

            };
            //添加新用户
            int resultCount = db.RunProcedure("Gp_InsertB", parameters, out resultCount);
            if (resultCount == 0)
            {
                string strSQL = "select typeid from btype where UserCode=" + FreeADO.DBUtility.DbHelperSQL.StrToSqlStr(userCode) + " and deleted =0";
                string typeid = db.Query(strSQL).Tables[0].Rows[0]["typeid"].ToString();
                db.ExecuteSql("update btype set denominatedid='" + typeid + "'  where usercode='" + userCode + "' and deleted =0");
            }
            return resultCount;
        }

        /// <summary>
        /// 修改btype
        /// </summary>
        /// <param name="UserCode"></param>
        /// <param name="fullName"></param>
        public static int UpdateBtype(DbHelperSQLP db, string userCode, string fullName, DataTable dt)
        {
            DataRow dr = dt.Rows[0];
            SqlParameter[] parameters ={
                new SqlParameter("@typeId",dr["typeId"].ToString()),
                new SqlParameter("@usercode", userCode),
                new SqlParameter("@FullName", fullName),
                new SqlParameter("@Name", dr["Name"].ToString()),
                new SqlParameter("@Area", dr["Area"].ToString()),
                new SqlParameter("@TelAndAddress", dr["TelAndAddress"].ToString()),
                new SqlParameter("@PostCode", dr["PostCode"].ToString()),
                new SqlParameter("@Person",dr["Person"].ToString()),
                new SqlParameter("@TaxNumber", dr["TaxNumber"].ToString()),
                new SqlParameter("@bankandacount", dr["BankAndAcount"].ToString()),
                new SqlParameter("@Artotal00", dr["ARTotal00"].ToString()),
                new SqlParameter("@Aptotal00", dr["APTotal00"].ToString()),
                new SqlParameter("@Comment", dr["Comment"].ToString()),
                new SqlParameter("@Client", dr["Client"].ToString()),
                new SqlParameter("@ARLimit", dr["ARLimit"].ToString()),
                new SqlParameter("@ARLimitTime",dr["ARLimitTime"].ToString()),
                new SqlParameter("@PaymentLTime", dr["paymentLTime"].ToString()),
                new SqlParameter("@Tel1", dr["Tel1"].ToString()),
                new SqlParameter("@Tel2", dr["Tel2"].ToString()),
                new SqlParameter("@Tel3",dr["Tel3"].ToString()),
                new SqlParameter("@WWW", dr["WWW"].ToString()),
                new SqlParameter("@Email", dr["Email"].ToString()),
                new SqlParameter("@Fax", dr["Fax"].ToString()),
                new SqlParameter("@Bank", dr["Bank"].ToString()),
                new SqlParameter("@BankName", dr["BankName"].ToString()),
                new SqlParameter("@LinkMan1",dr["LinkMan1"].ToString()),
                new SqlParameter("@LinkSex1", dr["LinkSex1"].ToString()),
                new SqlParameter("@LinkBirthDay1",  dr["LinkBirthDay1"].ToString()),
                new SqlParameter("@LinkJob1", dr["LinkJob1"].ToString()),
                new SqlParameter("@LinkCall1", dr["LinkCall1"].ToString()),
                new SqlParameter("@LinkTel1", dr["LinkTel1"].ToString()),
                new SqlParameter("@LinkMobile1", dr["LinkMobile1"].ToString()),
                new SqlParameter("@LinkEMail1",  dr["LinkEMail1"].ToString()),
                new SqlParameter("@LinkPost1", dr["LinkPost1"].ToString()),
                new SqlParameter("@LinkAddress1",dr["LinkAddress1"].ToString()),
                new SqlParameter("@LinkComment1", dr["LinkComment1"].ToString()),
                new SqlParameter("@LinkMan2", dr["LinkMan2"].ToString()),
                new SqlParameter("@LinkSex2",dr["LinkSex2"].ToString()),
                new SqlParameter("@LinkBirthDay2", dr["LinkBirthDay2"].ToString()),
                new SqlParameter("@LinkJob2", dr["LinkJob2"].ToString()),
                new SqlParameter("@LinkCall2", dr["LinkCall2"].ToString()),
                new SqlParameter("@LinkTel2", dr["LinkTel2"].ToString()),
                new SqlParameter("@LinkMobile2", dr["LinkMobile2"].ToString()),
                new SqlParameter("@LinkEMail2", dr["LinkEMail2"].ToString()),
                new SqlParameter("@LinkPost2", dr["LinkPost2"].ToString()),
                new SqlParameter("@LinkAddress2", dr["LinkAddress2"].ToString()),
                new SqlParameter("@LinkComment2", dr["LinkComment2"].ToString()),
                new SqlParameter("@CreateDate",dr["CreateDate"].ToString()),
                new SqlParameter("@SaleZeKou",dr["SaleZeKou"].ToString()),
                new SqlParameter("@BuyZeKou",dr["BuyZeKou"].ToString()),
                new SqlParameter("@PyCode", FreeADO.Common.StringPlus.GetFirstPYLetter(fullName)),
                new SqlParameter("@Price", dr["Price"].ToString()),
                new SqlParameter("@AreaTypeID", dr["AreaTypeID"].ToString()),
                new SqlParameter("@IFStype", 1),
                new SqlParameter("@etypeid", dr["etypeid"].ToString()),
                new SqlParameter("@buyprice", dr["buyprice"].ToString()),
                new SqlParameter("@consignee", dr["Consignee"].ToString()),
                new SqlParameter("@consigneetel", dr["ConsigneeTel"].ToString()),
                new SqlParameter("@consigneeaddress",dr["ConsigneeAddress"].ToString()),
                new SqlParameter("@valeditprice", dr["cannotmodIFyprice"].ToString()),
                new SqlParameter("@denominatedid", dr["denominatedid"].ToString()),
                new SqlParameter("@backlimitday", dr["BackLimitDay"].ToString()),
                new SqlParameter("@backpercent", dr["BackPercent"].ToString()),
                new SqlParameter("@cid", dr["Cid"].ToString()),
                new SqlParameter("@pricetrackenable",  dr["PriceTrackEnable"].ToString()),
                new SqlParameter("@cqdays", dr["cqdays"].ToString()),
                new SqlParameter("@chkskmonthday", dr["chkskmonthday"].ToString()),
                new SqlParameter("@skmonthday", dr["skmonthday"].ToString()),
                new SqlParameter("@chkfkmonthday", dr["chkfkmonthday"].ToString()),
                new SqlParameter("@fkmonthday", dr["fkmonthday"].ToString()),
                new SqlParameter("@dzdays", dr["dzdays"].ToString()),
                new SqlParameter("@dzwarningdays", dr["dzwarningdays"].ToString()),
                new SqlParameter("@ckarlimittime", dr["ckarlimittime"].ToString()),
                new SqlParameter("@ckpaymentltime",dr["ckpaymentltime"].ToString()),
                new SqlParameter("@fkcqdays", dr["fkcqdays"].ToString()),
                new SqlParameter("@fkdzdays", dr["fkdzdays"].ToString()),
                new SqlParameter("@fkdzwarningdays", dr["fkdzwarningdays"].ToString()),
                new SqlParameter("@iscarrier", dr["iscarrier"].ToString()),
                new SqlParameter("@sheng", dr["sheng"].ToString()),
                new SqlParameter("@shi", dr["shi"].ToString()),
                new SqlParameter("@xian", dr["xian"].ToString()),
                new SqlParameter("@blevel", dr["blevel"].ToString()),

                new SqlParameter("@isusebrandartype", dr["isusebrandartype"].ToString()),//   BIT=0,                  --是否启用品牌应收
                new SqlParameter("@skmonth", dr["skmonth"].ToString()),//   VARCHAR(10) = NULL,     --收款第几月
                new SqlParameter("@skday", dr["skday"].ToString()),//   VARCHAR(10) = NULL,     --收款第几日
                new SqlParameter("@skdzdayflag", dr["skdzdayflag"].ToString()),//   VARCHAR(10) = '0',      --按对账日期计算收款期限
                new SqlParameter("@fkmonth", dr["fkmonth"].ToString()),//   VARCHAR(10) = NULL,     --付款第几月
                new SqlParameter("@fkday", dr["fkday"].ToString()),//   VARCHAR(10) = NULL,     --付款第几日
                new SqlParameter("@fkdzdayflag", dr["fkdzdayflag"].ToString()),//   VARCHAR(10) = '0',      --按对账日期计算付款期限
                new SqlParameter("@skcyjartime", dr["skcyjartime"].ToString()),//   VARCHAR(10) = '0',      --收款次月结
                new SqlParameter("@fkcyjaptime", dr["fkcyjaptime"].ToString()),//   VARCHAR(10) = '0',      --付款次月结
                new SqlParameter("@operatorid", dr["operatorid"].ToString()),//   VARCHAR(50) = '',       --当前操作员
                new SqlParameter("@shopbtypeid",dr["shopbtypeid"].ToString()),//   INT = 0,                --用户组ID
                new SqlParameter("@stypeid", dr["chainstypeid"].ToString()),//   VARCHAR(50) = ''        --分支机构ID
            };
            //添加新用户
            int resultCount = db.RunProcedure("Gp_UpdateB", parameters, out resultCount);
            if (resultCount == 0)
            {
                string strSQL = "select typeid from btype where UserCode=" + FreeADO.DBUtility.DbHelperSQL.StrToSqlStr(userCode) + " and deleted =0";
                string typeid = db.Query(strSQL).Tables[0].Rows[0]["typeid"].ToString();
                db.ExecuteSql("update btype set denominatedid='" + typeid + "'  where usercode='" + userCode + "' and deleted =0");
            }
            return resultCount;
        }
        #endregion
    }

    public class AdDebtBill
    {
        public decimal BillNumberId { get; set; } = 0;
        public string BtypeId { get; set; } = "";
        public decimal total { get; set; } = 0;
        public string Comment { get; set; } = "";
        public string STypeID { get; set; } = "";
        public decimal ntotal { get; set; } = 0;
        public decimal NCompleteTotal { get; set; } = 0;
        public decimal CompleteTotal { get; set; } = 0;
        public int ShowOrder { get; set; } = 0;
        public int AlertDay { get; set; } = 0;
        public string brandartypeid { get; set; } = "";


    }

    public class DtypeIdAndStypeIdModel
    {
        public string DtypeId { get; set; }
        public string StypeId { get; set; }
    }

    public class OtertBillIndexModel
    {
        public string OuterNo { get; set; }
        public string WarehouseNo { get; set; }
        public string Remark { get; set; }
        public decimal BillNumberId { get; set; }

    }
    public class OtherSaleBillModel
    {
        public string SpecNo { get; set; }
        public decimal? Num { get; set; }
        public string Remark { get; set; }
        public string BatchNo { get; set; }
        //public string PositionNo { get; set; }
    }


    public class BuyBillModel
    {

        public decimal BillNumberID { get; set; }
        public string PTypeID { get; set; }
        public decimal Qty { get; set; }
        public decimal SalePrice { get; set; }
        public decimal Discount { get; set; }
        public decimal DiscountPrice { get; set; }
        public string Jobno { get; set; }
        public decimal Total { get; set; }
        public DateTime MakeDate { get; set; }
        public decimal TaxPrice { get; set; }
        public decimal TaxTotal { get; set; }
        public string Comment { get; set; }
        public int OrderID { get; set; }
        public int intIsUnit2 { get; set; }
        public string Serial { get; set; }
        public string GoodsNumber { get; set; }
        public string ProduceDate { get; set; }
        public string ValidDate { get; set; }
        public string GoodsBTypeID { get; set; }
        public decimal Tax { get; set; }
        public decimal SaleTotal { get; set; }
        public string KTypeID { get; set; }
        public string STypeID { get; set; }
        public decimal FromBillNumberID { get; set; }
        public decimal FromBillID { get; set; }
        public decimal TaxMoney { get; set; }
        public decimal NSalePrice { get; set; }
        public decimal NSaleTotal { get; set; }
        public decimal NDiscountPrice { get; set; }
        public decimal NTotal { get; set; }
        public decimal NTaxPrice { get; set; }
        public decimal NTaxTotal { get; set; }
        public decimal NTaxMoney { get; set; }
        public int CargoId { get; set; }
        public int UnitId { get; set; }
        public int NUnitId { get; set; }
        public decimal NQty { get; set; }
        public decimal UnitRate { get; set; }
        public string NUnitMsg { get; set; }
        public int MUnitId { get; set; }
        public decimal MQty { get; set; }
        public decimal MUnitRate { get; set; }
        public string MUnitMsg { get; set; }
        public decimal MSalePrice { get; set; }
        public decimal MDiscountPrice { get; set; }
        public decimal MTaxPrice { get; set; }
        public decimal CurMSalePrice { get; set; }
        public decimal CurMDiscountPrice { get; set; }
        public decimal CurMTaxPrice { get; set; }
        public long ItemId { get; set; }
        public int IsCombined { get; set; }
        public decimal CompleteQty { get; set; }
        public string entryCode { get; set; }
        public decimal InvoiceQty { get; set; }
        public decimal InvoiceMoney { get; set; }
        public decimal NInvoiceMoney { get; set; }
        public int IsGift { get; set; }
        public decimal CompleteTotal { get; set; }
        public decimal NCompleteTotal { get; set; }
        public decimal LendBillID { get; set; }
        public decimal LendBillNumberID { get; set; }
        public int ID { get; set; }
        public int ShowOrder { get; set; }
        public int AskBillID { get; set; }
        public int AskBillNumberID { get; set; }
        public string PriceSource { get; set; }
        public BuyBillModel()
        {

            BillNumberID = 0;
            PTypeID = "";
            Qty = 0;
            SalePrice = 0;
            Discount = 0;
            DiscountPrice = 0;
            Jobno = "";
            Total = 0;
            MakeDate = DateTime.Now;
            TaxPrice = 0;
            TaxTotal = 0;
            Comment = "";
            OrderID = 0;
            intIsUnit2 = 0;
            Serial = "";
            GoodsNumber = "";
            ProduceDate = "";
            ValidDate = "";
            GoodsBTypeID = "";
            DiscountPrice = 0;
            Tax = 0;
            SaleTotal = 0;
            KTypeID = "";
            STypeID = "";
            FromBillNumberID = 0;
            FromBillID = 0;
            TaxMoney = 0;
            NSalePrice = 0;
            NSaleTotal = 0;
            NDiscountPrice = 0;
            NTotal = 0;
            NTaxPrice = 0;
            NTaxTotal = 0;
            NTaxMoney = 0;
            CargoId = 0;
            UnitId = 0;
            NUnitId = 0;
            NQty = 0;
            UnitRate = 0;
            NUnitMsg = "";
            MUnitId = 0;
            MQty = 0;
            MUnitRate = 0;
            MUnitMsg = "";
            MSalePrice = 0;
            MDiscountPrice = 0;
            MTaxPrice = 0;
            CurMSalePrice = 0;
            CurMDiscountPrice = 0;
            CurMTaxPrice = 0;
            ItemId = 0;
            IsCombined = 0;
            CompleteQty = 0;
            entryCode = "";
            InvoiceQty = 0;
            NInvoiceMoney = 0;
            InvoiceMoney = 0;
            IsGift = 0;
            CompleteTotal = 0;
            NCompleteTotal = 0;
            LendBillID = 0;
            LendBillNumberID = 0;
            ShowOrder = 0;
            AskBillID = 0;
            AskBillNumberID = 0;
            PriceSource = "";
            ID = 0;
        }
    }

    public class BuyBackBillModel
    {
        /// <summary>
        /// 
        /// </summary>
        public int BillNumberId { get; set; }
        /// <summary>
        /// 
        /// </summary>
        public string PtypeId { get; set; }
        /// <summary>
        /// 
        /// </summary>
        public decimal Qty { get; set; }
        /// <summary>
        /// 
        /// </summary>
        public decimal SalePrice { get; set; }
        /// <summary>
        /// 
        /// </summary>
        public decimal discount { get; set; }
        /// <summary>
        /// 
        /// </summary>
        public decimal DiscountPrice { get; set; }
        /// <summary>
        /// 
        /// </summary>
        public string jobno { get; set; }
        /// <summary>
        /// 
        /// </summary>
        public decimal total { get; set; }
        /// <summary>
        /// 
        /// </summary>
        public DateTime makedate { get; set; }
        /// <summary>
        /// 
        /// </summary>
        public decimal TaxPrice { get; set; }
        /// <summary>
        /// 
        /// </summary>
        public decimal TaxTotal { get; set; }
        /// <summary>
        /// 
        /// </summary>
        public string comment { get; set; }
        /// <summary>
        /// 
        /// </summary>
        public int intIsUnit2 { get; set; }
        /// <summary>
        /// 
        /// </summary>
        public string Serial { get; set; }
        /// <summary>
        /// 
        /// </summary>
        public string OldID { get; set; }
        /// <summary>
        /// 
        /// </summary>
        public decimal OldBillNumberID { get; set; }
        /// <summary>
        /// 
        /// </summary>
        public decimal InputCostPrice { get; set; }
        /// <summary>
        /// 
        /// </summary>
        public string GoodsNumber { get; set; }
        /// <summary>
        /// 
        /// </summary>
        public string ProduceDate { get; set; }
        /// <summary>
        /// 
        /// </summary>
        public string ValidDate { get; set; }
        /// <summary>
        /// 
        /// </summary>
        public string GoodsBTypeID { get; set; }
        /// <summary>
        /// 
        /// </summary>
        public decimal GoodsCostPrice { get; set; }
        /// <summary>
        /// 
        /// </summary>
        public int HandZeroCost { get; set; }
        /// <summary>
        /// 
        /// </summary>
        public decimal Tax { get; set; }
        /// <summary>
        /// 
        /// </summary>
        public decimal SaleTotal { get; set; }
        /// <summary>
        /// 
        /// </summary>
        public string KTypeID { get; set; }
        /// <summary>
        /// 
        /// </summary>
        public string STypeID { get; set; }
        /// <summary>
        /// 
        /// </summary>
        public decimal TaxMoney { get; set; }
        /// <summary>
        /// 
        /// </summary>
        public decimal NSalePrice { get; set; }
        /// <summary>
        /// 
        /// </summary>
        public decimal NSaleTotal { get; set; }
        /// <summary>
        /// 
        /// </summary>
        public decimal NDiscountPrice { get; set; }
        /// <summary>
        /// 
        /// </summary>
        public decimal NTotal { get; set; }
        /// <summary>
        /// 
        /// </summary>
        public decimal NTaxPrice { get; set; }
        /// <summary>
        /// 
        /// </summary>
        public decimal NTaxTotal { get; set; }
        /// <summary>
        /// 
        /// </summary>
        public decimal NTaxMoney { get; set; }
        /// <summary>
        /// 
        /// </summary>
        public decimal CargoId { get; set; }
        /// <summary>
        /// 
        /// </summary>
        public int UnitId { get; set; }
        /// <summary>
        /// 
        /// </summary>
        public int NUnitId { get; set; }
        /// <summary>
        /// 
        /// </summary>
        public decimal NQty { get; set; }
        /// <summary>
        /// 
        /// </summary>
        public decimal UnitRate { get; set; }
        /// <summary>
        /// 
        /// </summary>
        public string NUnitMsg { get; set; }
        /// <summary>
        /// 
        /// </summary>
        public int MUnitId { get; set; }
        /// <summary>
        /// 
        /// </summary>
        public decimal MQty { get; set; }
        /// <summary>
        /// 
        /// </summary>
        public decimal MUnitRate { get; set; }
        /// <summary>
        /// 
        /// </summary>
        public string MUnitMsg { get; set; }
        /// <summary>
        /// 
        /// </summary>
        public decimal MSalePrice { get; set; }
        /// <summary>
        /// 
        /// </summary>
        public decimal MDiscountPrice { get; set; }
        /// <summary>
        /// 
        /// </summary>
        public decimal MTaxPrice { get; set; }
        /// <summary>
        /// 
        /// </summary>
        public decimal CurMSalePrice { get; set; }
        /// <summary>
        /// 
        /// </summary>
        public decimal CurMDiscountPrice { get; set; }
        /// <summary>
        /// 
        /// </summary>
        public decimal CurMTaxPrice { get; set; }
        /// <summary>
        /// 
        /// </summary>
        public int ItemId { get; set; }
        /// <summary>
        /// 
        /// </summary>
        public int IsCombined { get; set; }
        /// <summary>
        /// 
        /// </summary>
        public decimal CompleteQty { get; set; }
        /// <summary>
        /// 
        /// </summary>
        public decimal InvoiceQty { get; set; }
        /// <summary>
        /// 
        /// </summary>
        public decimal InvoiceMoney { get; set; }
        /// <summary>
        /// 
        /// </summary>
        public decimal NInvoiceMoney { get; set; }
        /// <summary>
        /// 
        /// </summary>
        public decimal IsGift { get; set; }
        /// <summary>
        /// 
        /// </summary>
        public decimal PriceStyle { get; set; }
        /// <summary>
        /// 
        /// </summary>
        public decimal CompleteTotal { get; set; }
        /// <summary>
        /// 
        /// </summary>
        public decimal NCompleteTotal { get; set; }
        /// <summary>
        /// 
        /// </summary>
        public int ID { get; set; }
        /// <summary>
        /// 
        /// </summary>
        public int ShowOrder { get; set; }
        /// <summary>
        /// 最近价跟踪
        /// </summary>
        public string PriceSource { get; set; }
        public BuyBackBillModel()
        {
            BillNumberId = 0;
            PtypeId = "";
            Qty = 0;
            SalePrice = 0;
            discount = 0;
            DiscountPrice = 0;
            jobno = "";
            total = 0;
            makedate = DateTime.Now;
            TaxPrice = 0;
            TaxTotal = 0;
            comment = "";
            intIsUnit2 = 0;
            Serial = "";
            OldID = "";
            OldBillNumberID = 0;
            InputCostPrice = 0;
            GoodsNumber = "";
            ProduceDate = "";
            ValidDate = "";
            GoodsBTypeID = "";
            GoodsCostPrice = -1;
            HandZeroCost = 0;
            Tax = 0;
            SaleTotal = 0;
            KTypeID = "";
            STypeID = "";
            TaxMoney = 0;
            NSalePrice = 0;
            NSaleTotal = 0;
            NDiscountPrice = 0;
            NTotal = 0;
            NTaxPrice = 0;
            NTaxTotal = 0;
            NTaxMoney = 0;
            CargoId = 0;
            UnitId = 1;
            NUnitId = 0;
            NQty = 0;
            UnitRate = 0;
            NUnitMsg = "";
            MUnitId = 1;
            MQty = 0;
            MUnitRate = 1;
            MUnitMsg = "";
            MSalePrice = 0;
            MDiscountPrice = 0;
            MTaxPrice = 0;
            CurMSalePrice = 0;
            CurMDiscountPrice = 0;
            CurMTaxPrice = 0;
            ItemId = 0;
            IsCombined = 0;
            CompleteQty = 0;
            InvoiceQty = 0;
            InvoiceMoney = 0;
            NInvoiceMoney = 0;
            IsGift = 0;
            PriceStyle = 0;
            CompleteTotal = 0;
            NCompleteTotal = 0;
            ShowOrder = 0;
            ID = 0;
            PriceSource = "最近价跟踪";
        }
    }


    public class MoveBillParm
    {
        public int BillNumberId { get; set; }
        public string PtypeId { get; set; }
        public decimal Qty { get; set; }
        public decimal Price { get; set; }
        public decimal Total { get; set; }
        public string Comment { get; set; }
        public int IsUnit2 { get; set; }
        public string Serial { get; set; }
        public decimal InputCostPrice { get; set; }
        public string GoodsNumber { get; set; }
        public string ProduceDate { get; set; }
        public string ValidDate { get; set; }
        public string GoodsBTypeID { get; set; }
        public decimal GoodsCostPrice { get; set; }
        public int HandZeroCost { get; set; }
        public string STypeID { get; set; }
        public string KTypeId { get; set; }
        public string KTypeId2 { get; set; }
        public int UnitId { get; set; }
        public int NUnitId { get; set; }
        public decimal NQty { get; set; }
        public decimal UnitRate { get; set; }
        public string NUnitMsg { get; set; }
        public int MUnitId { get; set; }
        public decimal MQty { get; set; }
        public decimal MUnitRate { get; set; }
        public string MUnitMsg { get; set; }
        public decimal MPrice { get; set; }
        public int Incargoid { get; set; }
        public int Outcargoid { get; set; }
        public int ItemId { get; set; }
        public int IsCombined { get; set; }
        public int AllotID { get; set; }
        public int ShowOrder { get; set; }
        public string ProjectId1 { get; set; }
        public string ProjectId2 { get; set; }
        public MoveBillParm()
        {
            BillNumberId = 0;
            PtypeId = "";
            Qty = 0;
            Price = 0;
            Total = 0;
            Comment = "";
            IsUnit2 = 0;
            Serial = "";
            InputCostPrice = 0;
            GoodsNumber = "";
            ProduceDate = "";
            ValidDate = "";
            GoodsBTypeID = "";
            GoodsCostPrice = 0;
            HandZeroCost = 0;
            STypeID = "";
            KTypeId = "";
            KTypeId2 = "";
            UnitId = 0;
            NUnitId = 0;
            NQty = 0;
            UnitRate = 0;
            NUnitMsg = "";
            MUnitId = 0;
            MQty = 0;
            MUnitRate = 0;
            MUnitMsg = "";
            MPrice = 0;
            Incargoid = 0;
            Outcargoid = 0;
            ItemId = 0;
            IsCombined = 0;
            ShowOrder = 0;
            AllotID = 0;
            ProjectId1 = "";
            ProjectId2 = "";
        }
    }

    public class OrderIndexParam
    {
        public string BtypeId { get; set; }
        public string EtypeId { get; set; }
        public string KtypeId { get; set; }
        public DateTime? BillDate { get; set; }
        public string BillCode { get; set; }
        public int BillType { get; set; }
        public decimal TotalMoney { get; set; }
        public decimal TotalQty { get; set; }
        public int Period { get; set; }
        public bool Checked { get; set; }
        public bool RedWord { get; set; }
        public string Explain { get; set; }
        public DateTime? ReachDate { get; set; }
        public string Comment { get; set; }
        public string Checke { get; set; }
        public decimal Tax { get; set; }
        public int BillStatus { get; set; }
        public string etypeid2 { get; set; }
        public string WayMode { get; set; }
        public string WayBillCode { get; set; }
        public string GoodsNumber { get; set; }
        public string PackWay { get; set; }
        public string TEL { get; set; }
        public string DtypeId { get; set; }
        public string STypeID { get; set; }
        public decimal CustomerTotal { get; set; }
        public decimal NCustomerTotal { get; set; }
        public decimal NTotalMoney { get; set; }
        public int CId { get; set; }
        public decimal Rate { get; set; }
        public int BillProperty { get; set; }
        public string dealbtypeid { get; set; }
        public int isyapi { get; set; }
        public string yapiorderid { get; set; }
        public decimal Discount { get; set; }
        public string ATypeID { get; set; }
        // public decimal TotalInMoney { get; set; }
        public decimal NTotalInMoney { get; set; }
        public int VipCardID { get; set; }
        public string ProjectID { get; set; }
        public OrderIndexParam()
        {
            BtypeId = "";
            EtypeId = "00001";
            KtypeId = "";
            BillDate = null;
            BillCode = "";
            BillType = 0;
            TotalMoney = 0;
            TotalQty = 0;
            Period = 1;
            Checked = false;
            RedWord = false;
            Explain = "";
            ReachDate = null;
            Comment = "";
            Checke = "";
            Tax = 0;
            BillStatus = 0;
            etypeid2 = "";
            WayMode = "";
            WayBillCode = "";
            GoodsNumber = "";
            PackWay = "";
            TEL = "";
            DtypeId = "";
            STypeID = "00001";
            CustomerTotal = 0;
            NCustomerTotal = 0;
            NTotalMoney = 0;
            CId = 0;
            Rate = 0;
            BillProperty = 0;
            dealbtypeid = "";
            isyapi = 0;
            yapiorderid = "";
            Discount = 1;
            ATypeID = "";
            //  TotalInMoney = 0;
            NTotalInMoney = 0;
            VipCardID = -1;
            ProjectID = "";
        }
    }
    public class OrderBillModel
    {
        public string chvPTypeID { get; set; }
        public decimal numQty { get; set; }
        public decimal numPrice { get; set; }
        public decimal numTotal { get; set; }
        public string chvComment { get; set; }
        public int intOrderID { get; set; } //v3没有
        public int intIsUnitTow { get; set; }
        public decimal numReachQty { get; set; }
        public decimal numDiscount { get; set; }
        public decimal numDiscountPrice { get; set; }
        public decimal numTaxPrice { get; set; }
        public decimal numTaxTotal { get; set; }
        public decimal numSaleTotal { get; set; }
        public decimal numTax { get; set; }
        public string KTypeID { get; set; }
        public string STypeID { get; set; }
        public int FromBillNumberID { get; set; }
        public int FromBillID { get; set; }
        public int requestbillnumberid { get; set; }
        public int requestbillid { get; set; }
        public int askbillnumberid { get; set; }
        public int askbillid { get; set; }
        public decimal TaxMoney { get; set; }
        public decimal NSalePrice { get; set; }
        public decimal NSaleTotal { get; set; }
        public decimal NDiscountPrice { get; set; }
        public decimal NTotal { get; set; }
        public decimal NTaxPrice { get; set; }
        public decimal NTaxTotal { get; set; }
        public decimal NTaxMoney { get; set; }
        public int UnitId { get; set; }
        public int NUnitId { get; set; }
        public decimal NQty { get; set; }
        public decimal UnitRate { get; set; }
        public string NUnitMsg { get; set; }
        public int MUnitId { get; set; }
        public decimal MQty { get; set; }
        public decimal MUnitRate { get; set; }
        public string MUnitMsg { get; set; }
        public decimal MSalePrice { get; set; }
        public decimal MDiscountPrice { get; set; }
        public decimal MTaxPrice { get; set; }
        public decimal CurMSalePrice { get; set; }
        public decimal CurMDiscountPrice { get; set; }
        public decimal CurMTaxPrice { get; set; }
        public int ItemId { get; set; }
        public int IsCombined { get; set; }
        public string GoodsNumber { get; set; }
        public int CargoID { get; set; }
        public decimal GoodsCostPrice { get; set; }
        public int GoodsOrder { get; set; }
        public string ProduceDate { get; set; }
        public string ValidDate { get; set; }
        public int isrequest { get; set; }
        public decimal oldcurmtaxprice { get; set; }
        public decimal oldqty { get; set; }
        public string entrycode { get; set; }
        public int isgift { get; set; }
        public string YapiID { get; set; }
        public string PriceSource { get; set; }
        public int OrderId { get; set; }
        public int Id { get; set; }
        public int PromoType { get; set; }
        public int ShowOrder { get; set; }
        public decimal SaleOrderReachQty { get; set; }
        public int SaleOrderId { get; set; }
        public int PTCombinOrderBillDetailID { get; set; }
        //   public int PTCombinOrderBillDetailID { get; set; }  //v3没有
        public OrderBillModel()
        {
            chvPTypeID = "";
            numQty = 0;
            numPrice = 0;
            numTotal = 0;
            chvComment = "";
            intOrderID = 0; //v3没有
            intIsUnitTow = 0;
            numReachQty = 0;
            numDiscount = 1;
            numDiscountPrice = 0;
            numTaxPrice = 0;
            numTaxTotal = 0;
            numSaleTotal = 0;
            numTax = 0;
            KTypeID = "";
            STypeID = "";
            FromBillNumberID = 0;
            FromBillID = 0;
            requestbillnumberid = 0;
            requestbillid = 0;
            askbillnumberid = 0;
            askbillid = 0;
            TaxMoney = 0;
            NSalePrice = 0;
            NSaleTotal = 0;
            NDiscountPrice = 0;
            NTotal = 0;
            NTaxPrice = 0;
            NTaxTotal = 0;
            NTaxMoney = 0;
            UnitId = 1;
            NUnitId = 0;
            NQty = 0;
            UnitRate = 0;
            NUnitMsg = "";
            MUnitId = 1;
            MQty = 0;
            MUnitRate = 0;
            MUnitMsg = "";
            MSalePrice = 0;
            MDiscountPrice = 0;
            MTaxPrice = 0;
            CurMSalePrice = 0;
            CurMDiscountPrice = 0;
            CurMTaxPrice = 0;
            ItemId = 0;
            IsCombined = 0;
            GoodsNumber = "";
            CargoID = 0;
            GoodsCostPrice = 0;
            GoodsOrder = -1;
            ProduceDate = "";
            ValidDate = "";
            isrequest = 0;
            oldcurmtaxprice = 0;
            oldqty = 0;
            entrycode = "";
            isgift = 0;
            YapiID = "";
            PriceSource = "";
            OrderId = 0;
            Id = 0;
            PromoType = 0;
            ShowOrder = 0;
            SaleOrderReachQty = 0;
            SaleOrderId = 0;
            PTCombinOrderBillDetailID = 0;  

        }
    }
    public class BillIndexParam
    {
        public DateTime? BillDate { get; set; }
        public string BillCode { get; set; }
        public decimal BillType { get; set; }
        public string Comment { get; set; }
        public string AtypeId { get; set; }
        public string PtypeId { get; set; }
        public string BtypeId { get; set; }
        public string EtypeId { get; set; }
        public string KtypeId { get; set; }
        public string KtypeId2 { get; set; }
        public string IfCheck { get; set; }
        public string CheckE { get; set; }
        public decimal TotalMoney { get; set; }
        public decimal TotalQty { get; set; }
        public decimal TotalInMoney { get; set; }
        public decimal Tax { get; set; }
        public int szPeriod { get; set; }
        public string Explain { get; set; }
        public bool Draft { get; set; }
        public bool RedWord { get; set; }
        public decimal OrderId { get; set; }
        public string WayBillCode { get; set; }
        public string Goodsnumber { get; set; }
        public string PackWay { get; set; }
        public string Tel { get; set; }
        public decimal preferencemoney { get; set; }
        public int AlertDay { get; set; }
        public string Assessor { get; set; }
        public string IfAudit { get; set; }
        public string Audit_explain { get; set; }
        public string DtypeId { get; set; }
        public int VipCardID { get; set; }
        public string KTypeID3 { get; set; }
        public string LinkMan { get; set; }
        public string LinkTel { get; set; }
        public string LinkAddr { get; set; }
        public string wxManID { get; set; }
        public string JieJianBillNumberID { get; set; }
        public string JieJianID { get; set; }
        public string BaoXiuBillNumberID { get; set; }
        public string BaoXiuID { get; set; }
        public string BuyDate { get; set; }
        public string Serial { get; set; }
        public decimal wxTotal { get; set; }
        public string ErrDes { get; set; }
        public int ifHideJieJian { get; set; }
        public int ifWX { get; set; }
        public int IfBargainOn { get; set; }
        public string STypeID { get; set; }
        public decimal FromBillNumberID { get; set; }
        public bool CostSale { get; set; }
        public DateTime? completedate { get; set; }
        public int billstate { get; set; }
        public int ifmulaccount { get; set; }
        public decimal vipczmoney { get; set; }
        public int otherinouttype { get; set; }
        public decimal czbeforetimes { get; set; }
        public int PosBillType { get; set; }
        public string TransportId { get; set; }
        public int IsFreightMoney { get; set; }
        public string FreightAddr { get; set; }
        public string FreightPerson { get; set; }
        public string FreightTel { get; set; }
        public int ShareMode { get; set; }
        public string uf1 { get; set; }
        public string uf2 { get; set; }
        public string uf3 { get; set; }
        public string uf4 { get; set; }
        public string uf5 { get; set; }
        public string DEALBTYPEID { get; set; }
        public int cid { get; set; }
        public decimal rate { get; set; }
        public decimal ntotalmoney { get; set; }
        public decimal ntotalinmoney { get; set; }
        public decimal npreferencemoney { get; set; }
        public decimal nvipczmoney { get; set; }
        public string atypeid1 { get; set; }
        public int billproperty { get; set; }
        public decimal ncompletetotal { get; set; }
        public bool isini { get; set; }
        public int ATID { get; set; }
        public decimal completetotal { get; set; }
        public bool IfCargo { get; set; }
        public int IfInvoice { get; set; }
        public decimal invoicemoney { get; set; }
        public decimal ninvoicemoney { get; set; }
        public int importtype { get; set; }
        public int AssetBusinessTypeId { get; set; }
        public int promoruleid { get; set; }
        public int beforepromobillnumberid { get; set; }
        public string promotionmsg { get; set; }
        public string STypeID2 { get; set; }
        public int ifconfirm { get; set; }
        public int FeeDeductType { get; set; }
        public int TransferType { get; set; }
        public int isyapi { get; set; }
        public string yapiorderid { get; set; }
        public string DeliveryAddress { get; set; }
        public decimal Discount { get; set; }
        public int AdpriceType { get; set; }
        public string checkSave { get; set; }
        public string chargeoffbtypeid { get; set; }
        public int chargeofftype { get; set; }
        public decimal chargeofftotal { get; set; }
        public decimal nchargeofftotal { get; set; }
        public int IsLend { get; set; }
        public int WarehouseOutDay { get; set; }
        public int StockInDeadline { get; set; }
        public bool IsNeedTransport { get; set; }
        public int iscombinationstyle { get; set; }
        public string transporterid { get; set; }
        public string transporterfullname { get; set; }
        public string shipperfullname { get; set; }
        public string shipperperson { get; set; }
        public string shippertel { get; set; }
        public string transportno { get; set; }
        public decimal totalfreight { get; set; }
        public decimal ntotalfreight { get; set; }
        public string PromonIds { get; set; }
        public int isByBrandarType { get; set; }
        public int NewPosBill { get; set; }
        public int PayOnTheSpot { get; set; }
        public int posid { get; set; }
        public int allowinvoicing { get; set; }
        public string ProjectID { get; set; }
        public int? UsePM { get; set; }
        public DateTime? Yjbxrq { get; set; }
        public BillIndexParam()
        {
            BillDate = null;
            Yjbxrq = null;
            UsePM = null;
            ProjectID = "";
            BillCode = "";
            BillType = 0;
            Comment = "";
            AtypeId = "";
            PtypeId = "";
            BtypeId = "";
            EtypeId = "";
            KtypeId = "";
            KtypeId2 = "";
            IfCheck = "";
            CheckE = "";
            TotalMoney = 0;
            TotalQty = 0;
            TotalInMoney = 0;
            Tax = 0;
            szPeriod = 0;
            Explain = "";
            Draft = false;
            RedWord = false;
            OrderId = 0;
            WayBillCode = "";
            Goodsnumber = "";
            PackWay = "";
            Tel = "";
            preferencemoney = 0;
            AlertDay = 9999;
            Assessor = "";
            IfAudit = "";
            Audit_explain = "";
            DtypeId = "";
            VipCardID = -1;
            KTypeID3 = "";
            LinkMan = "";
            LinkTel = "";
            LinkAddr = "";
            wxManID = "";
            JieJianBillNumberID = "";
            JieJianID = "";
            BaoXiuBillNumberID = "";
            BaoXiuID = "";
            BuyDate = "";
            Serial = "";
            wxTotal = 0;
            ErrDes = "";
            ifHideJieJian = 0;
            ifWX = 0;
            IfBargainOn = 0;
            STypeID = "";
            FromBillNumberID = 0;
            CostSale = false;
            completedate = null;
            billstate = 0;
            ifmulaccount = 0;
            vipczmoney = 0;
            otherinouttype = 0;
            czbeforetimes = 0;
            PosBillType = 0;
            TransportId = "";
            IsFreightMoney = 0;
            FreightAddr = "";
            FreightPerson = "";
            FreightTel = "";
            ShareMode = 0;
            uf1 = "";
            uf2 = "";
            uf3 = "";
            uf4 = "";
            uf5 = "";
            DEALBTYPEID = "";
            cid = 0;
            rate = 1;
            ntotalmoney = 0;
            ntotalinmoney = 0;
            npreferencemoney = 0;
            nvipczmoney = 0;
            atypeid1 = "";
            billproperty = 0;
            ncompletetotal = 0;
            isini = false;
            ATID = 0;
            completetotal = 0;
            IfCargo = false;
            IfInvoice = 0;
            invoicemoney = 0;
            ninvoicemoney = 0;
            importtype = 0;
            AssetBusinessTypeId = 0;
            promoruleid = 0;
            beforepromobillnumberid = 0;
            promotionmsg = "";
            STypeID2 = "";
            ifconfirm = 0;
            FeeDeductType = 0;
            TransferType = 1;
            isyapi = 0;
            yapiorderid = "0";
            DeliveryAddress = "";
            Discount = 1;
            AdpriceType = 0;
            checkSave = "";
            chargeoffbtypeid = "";
            chargeofftype = 0;
            chargeofftotal = 0;
            nchargeofftotal = 0;
            IsLend = 0;
            WarehouseOutDay = 9999;
            StockInDeadline = 9999;
            IsNeedTransport = false;
            iscombinationstyle = 0;
            transporterid = "0";
            transporterfullname = "";
            shipperfullname = "";
            shipperperson = "";
            shippertel = "";
            transportno = "";
            totalfreight = 0;
            ntotalfreight = 0;
            PromonIds = "";
            isByBrandarType = 0;
            NewPosBill = 0;
            PayOnTheSpot = 0;
            posid = 0;
            allowinvoicing = 1;
        }
    }
    public class SaleBillModel
    {

        public int BillNumberId { get; set; } = 0;
        public string PtypeId { get; set; } = "";
        public decimal Qty { get; set; } = 0;
        public decimal SalePrice { get; set; } = 0;
        public decimal Discount { get; set; } = 0;
        public decimal DiscountPrice { get; set; } = 0;
        public string Jobnumber { get; set; } = "";
        public decimal Total { get; set; } = 0;
        public DateTime? OutFactoryDate { get; set; } = null;
        public decimal TaxPrice { get; set; } = 0;
        public decimal TaxTotal { get; set; } = 0;
        public string Comment { get; set; } = "";
        public int OrderID { get; set; } = 0;
        public int intisUnitTow { get; set; } = 0;
        public string Serial { get; set; } = "";
        public decimal InputCostPrice { get; set; } = 0;
        public string GoodsNumber { get; set; } = "";
        public string ProduceDate { get; set; } = "";
        public string ValidDate { get; set; } = "";
        public string GoodsBTypeID { get; set; } = "";
        public decimal GoodsCostPrice { get; set; } = 0;
        public int HandZeroCost { get; set; } = 0;
        public decimal Tax { get; set; } = 0;
        public decimal SaleTotal { get; set; } = 0;
        public string KTypeID { get; set; } = "";
        public string STypeID { get; set; } = "";
        public decimal TaxMoney { get; set; } = 0;
        public decimal NSalePrice { get; set; } = 0;
        public decimal NSaleTotal { get; set; } = 0;
        public decimal NDiscountPrice { get; set; } = 0;
        public decimal NTotal { get; set; } = 0;
        public decimal NTaxPrice { get; set; } = 0;
        public decimal NTaxTotal { get; set; } = 0;
        public decimal NTaxMoney { get; set; } = 0;
        public int CargoId { get; set; } = 0;
        public int UnitId { get; set; } = 0;
        public int NUnitId { get; set; } = 0;
        public decimal NQty { get; set; } = 0;
        public decimal UnitRate { get; set; } = 0;
        public string NUnitMsg { get; set; } = "";
        public int MUnitId { get; set; } = 0;
        public decimal MQty { get; set; } = 0;
        public decimal MUnitRate { get; set; } = 0;
        public string MUnitMsg { get; set; } = "";
        public decimal MSalePrice { get; set; } = 0;
        public decimal MDiscountPrice { get; set; } = 0;
        public decimal MTaxPrice { get; set; } = 0;
        public decimal CurMSalePrice { get; set; } = 0;
        public decimal CurMDiscountPrice { get; set; } = 0;
        public decimal CurMTaxPrice { get; set; } = 0;
        public int ItemId { get; set; } = 0;
        public int IsCombined { get; set; } = 0;
        public decimal CompleteQTY { get; set; } = 0;
        public decimal CompleteTotal { get; set; } = 0;
        public decimal NCompleteTotal { get; set; } = 0;
        public string entryCode { get; set; } = "";
        public decimal InvoiceQty { get; set; } = 0;
        public decimal InvoiceMoney { get; set; } = 0;
        public decimal NInvoiceMoney { get; set; } = 0;
        public string PriceSource { get; set; } = "";
        public int IsGift { get; set; } = 0;
        public int BeforePromoID { get; set; } = 0;
        public decimal ReferPrice { get; set; } = 0;
        public int PriceStyle { get; set; } = 0;
        public int PromoType { get; set; } = 0;
        public int OMBillID { get; set; } = 0;
        public int LendBillID { get; set; } = 0;
        public int LendBillNumberID { get; set; } = 0;
        public int ID { get; set; } = 0;
        public int ShowOrder { get; set; } = 0;
        public int DiyID { get; set; } = 0;
        public bool iscombination { get; set; } = false;
        public string combinationptypeid { get; set; } = "";
        public string pindexid { get; set; } = "";
        public string ETypeID { get; set; } = "";
        public string PromonIds { get; set; } = "";
        public string CouponCode { get; set; } = "";
        public int IsPromotion { get; set; } = 0;
        public int IsVipPoint { get; set; } = 0;
        public int PriceDetailId  { get; set; } = 0;
        public int PriceRuleId { get; set; } = 0;


    }
    public class SaleBackModel
    {

        public int BillNumberId { get; set; }
        public string PtypeId { get; set; }
        public decimal Qty { get; set; }
        public decimal SalePrice { get; set; }
        public decimal Discount { get; set; }
        public decimal DiscountPrice { get; set; }
        public string JobNo { get; set; }
        public decimal Total { get; set; }
        public DateTime? MakeDate { get; set; }
        public decimal TaxPrice { get; set; }
        public decimal TaxTotal { get; set; }
        public string Comment { get; set; }
        public int intisUnit2 { get; set; }
        public string Serial { get; set; }
        public string OldID { get; set; }
        public int OldBillNumberID { get; set; }
        public decimal InputCostPrice { get; set; }
        public string GoodsNumber { get; set; }
        public string ProduceDate { get; set; }
        public string ValidDate { get; set; }
        public string GoodsBTypeID { get; set; }
        public decimal GoodsCostPrice { get; set; }
        public int HandZeroCost { get; set; }
        public decimal Tax { get; set; }
        public decimal SaleTotal { get; set; }
        public string KTypeID { get; set; }
        public string STypeID { get; set; }
        public decimal FromBillNumberID { get; set; }
        public decimal FromBillID { get; set; }
        public decimal TaxMoney { get; set; }
        public decimal NSalePrice { get; set; }
        public decimal NSaleTotal { get; set; }
        public decimal NDiscountPrice { get; set; }
        public decimal NTotal { get; set; }
        public decimal NTaxPrice { get; set; }
        public decimal NTaxTotal { get; set; }
        public decimal NTaxMoney { get; set; }
        public int CargoId { get; set; }
        public int UnitId { get; set; }
        public int NUnitId { get; set; }
        public decimal NQty { get; set; }
        public decimal UnitRate { get; set; }
        public string NUnitMsg { get; set; }
        public int MUnitId { get; set; }
        public decimal MQty { get; set; }
        public decimal MUnitRate { get; set; }
        public string MUnitMsg { get; set; }
        public decimal MSalePrice { get; set; }
        public decimal MDiscountPrice { get; set; }
        public decimal MTaxPrice { get; set; }
        public decimal CurMSalePrice { get; set; }
        public decimal CurMDiscountPrice { get; set; }
        public decimal CurMTaxPrice { get; set; }
        public int ItemId { get; set; }
        public int IsCombined { get; set; }
        public decimal CompleteQTY { get; set; }
        public decimal InvoiceQty { get; set; }
        public decimal InvoiceMoney { get; set; }
        public decimal NInvoiceMoney { get; set; }
        public int IsGift { get; set; }
        public decimal ReferPrice { get; set; }
        public int PriceStyle { get; set; }
        public int PromoType { get; set; }
        public int OMBillID { get; set; }
        public decimal CompleteTotal { get; set; }
        public decimal NCompleteTotal { get; set; }
        public int ID { get; set; }
        public int ShowOrder { get; set; }
        public string ETypeID { get; set; }
        public string PriceSource { get; set; }
        public string CouponCode { get; set; }


        public SaleBackModel()
        {
            BillNumberId = 0;
            PtypeId = "";
            Qty = 0;
            SalePrice = 0;
            Discount = 0;
            DiscountPrice = 0;
            JobNo = "";
            Total = 0;
            MakeDate = null;
            TaxPrice = 0;
            TaxTotal = 0;
            Comment = "";
            intisUnit2 = 0;
            Serial = "";
            OldID = "";
            OldBillNumberID = 0;
            InputCostPrice = 0;
            GoodsNumber = "";
            ProduceDate = "";
            ValidDate = "";
            GoodsBTypeID = "";
            GoodsCostPrice = 0;
            HandZeroCost = 0;
            Tax = 0;
            SaleTotal = 0;
            KTypeID = "";
            STypeID = "";
            FromBillNumberID = 0;
            FromBillID = 0;
            TaxMoney = 0;
            NSalePrice = 0;
            NSaleTotal = 0;
            NDiscountPrice = 0;
            NTotal = 0;
            NTaxPrice = 0;
            NTaxTotal = 0;
            NTaxMoney = 0;
            CargoId = 0;
            UnitId = 0;
            NUnitId = 0;
            NQty = 0;
            UnitRate = 0;
            NUnitMsg = "";
            MUnitId = 0;
            MQty = 0;
            MUnitRate = 0;
            MUnitMsg = "";
            MSalePrice = 0;
            MDiscountPrice = 0;
            MTaxPrice = 0;
            CurMSalePrice = 0;
            CurMDiscountPrice = 0;
            CurMTaxPrice = 0;
            ItemId = 0;
            IsCombined = 0;
            CompleteQTY = 0;
            InvoiceQty = 0;
            InvoiceMoney = 0;
            NInvoiceMoney = 0;
            IsGift = 0;
            ReferPrice = 0;
            PriceStyle = 0;
            PromoType = 0;
            OMBillID = 0;
            CompleteTotal = 0;
            NCompleteTotal = 0;
            ID = 0;
            ShowOrder = 0;
            ETypeID = "";
            PriceSource = "";
            CouponCode = "";

        }
    }
    public class GatheringBillModel
    {

        public int BillNumberId { get; set; }
        public string AtypeId { get; set; }
        public decimal Total { get; set; }
        public string Comment { get; set; }
        public string STypeID { get; set; }
        public string vipcardid { get; set; }
        public decimal ntotal { get; set; }
        public int RelevanceBillId { get; set; }
        public int ShowOrder { get; set; }
        public string brandartypeid { get; set; }
        public decimal preferencemoney { get; set; }
        public decimal npreferencemoney { get; set; }
        public string contractid { get; set; }

        public GatheringBillModel()
        {
            BillNumberId = 0;
            AtypeId = "";
            Total = 0;
            Comment = "";
            STypeID = "";
            vipcardid = "";
            ntotal = 0;
            RelevanceBillId = 0;
            ShowOrder = 0;
            brandartypeid = "";
            preferencemoney = 0;
            npreferencemoney = 0;
            contractid = "";
        }
    }
    public class RetailBillModel
    {

        public int BillNumberId { get; set; } = 0;
        public string PtypeId { get; set; } = "";
        public decimal Qty { get; set; } = 0;
        public decimal SalePrice { get; set; } = 0;
        public decimal Discount { get; set; } = 0;
        public decimal DiscountPrice { get; set; } = 0;
        public string Jobnumber { get; set; } = "";
        public decimal Total { get; set; } = 0;
        public decimal TaxPrice { get; set; } = 0;
        public decimal TaxTotal { get; set; } = 0;
        public string Comment { get; set; } = "";
        public int OrderID { get; set; } = 0;
        public int intIsUnit2 { get; set; } = 0;
        public string Serial { get; set; } = "";
        public string GoodsNumber { get; set; } = "";
        public string ProduceDate { get; set; } = "";
        public string ValidDate { get; set; } = "";
        public string GoodsBTypeID { get; set; } = "";
        public decimal GoodsCostPrice { get; set; } = 0;
        public int HandZeroCost { get; set; } = 0;
        public decimal InputCosPrice { get; set; } = 0;
        public decimal Tax { get; set; } = 0;
        public decimal SaleTotal { get; set; } = 0;
        public string STypeID { get; set; } = "";
        public decimal TaxMoney { get; set; } = 0;
        public decimal NSalePrice { get; set; } = 0;
        public decimal NSaleTotal { get; set; } = 0;
        public decimal NDiscountPrice { get; set; } = 0;
        public decimal NTotal { get; set; } = 0;
        public decimal NTaxPrice { get; set; } = 0;
        public decimal NTaxTotal { get; set; } = 0;
        public decimal NTaxMoney { get; set; } = 0;
        public int CargoId { get; set; } = 0;
        public int UnitId { get; set; } = 0;
        public int NUnitId { get; set; } = 0;
        public decimal NQty { get; set; } = 0;
        public decimal UnitRate { get; set; } = 0;
        public string NUnitMsg { get; set; } = "";
        public int MUnitId { get; set; } = 0;
        public decimal MQty { get; set; } = 0;
        public decimal MUnitRate { get; set; } = 0;
        public string MUnitMsg { get; set; } = "";
        public decimal MSalePrice { get; set; } = 0;
        public decimal MDiscountPrice { get; set; } = 0;
        public decimal MTaxPrice { get; set; } = 0;
        public decimal CurMSalePrice { get; set; } = 0;
        public decimal CurMDiscountPrice { get; set; } = 0;
        public decimal CurMTaxPrice { get; set; } = 0;
        public int ItemId { get; set; } = 0;
        public int IsCombined { get; set; } = 0;
        public decimal InvoiceQty { get; set; } = 0;
        public decimal InvoiceMoney { get; set; } = 0;
        public decimal NInvoiceMoney { get; set; } = 0;
        public int IsGift { get; set; } = 0;
        public int BeforePromoID { get; set; } = 0;
        public int PriceDetailId { get; set; } = 0;
        public int PriceRuleId { get; set; } = 0;
        public string PriceSource { get; set; } = "";
        public int PosId { get; set; } = 0;
        public decimal ReferPrice { get; set; } = 0;
        public int PriceStyle { get; set; } = 0;
        public int PromoType { get; set; } = 0;
        public string ETypeID { get; set; } = "";
        public int ShowOrder { get; set; } = 0;
        public int iscombination { get; set; } = 0;
        public string combinationptypeid { get; set; } = "";
        public string pindexid { get; set; } = "";
        public string KTypeID { get; set; } = "";
        public string PromonIds { get; set; } = "";
        public string CouponCode { get; set; } = "";
        public int IsPromotion { get; set; } = 0;
        public int IsVipPoint { get; set; } = 0;


    }
    public class RetailBackBillModel
    {

        public int BillNumberId { get; set; } = 0;
        public string PtypeId { get; set; } = "";
        public decimal Qty { get; set; } = 0;
        public decimal SalePrice { get; set; } = 0;
        public decimal Discount { get; set; } = 0;
        public decimal DiscountPrice { get; set; } = 0;
        public string Jobnumber { get; set; } = "";
        public decimal Total { get; set; } = 0;
        public DateTime? MakeDate { get; set; } = null;
        public decimal TaxPrice { get; set; } = 0;
        public decimal TaxTotal { get; set; } = 0;
        public string Comment { get; set; } = "";
        public int intisUnit2 { get; set; } = 0;
        public string Serial { get; set; } = "";
        public decimal InputCosPrice { get; set; } = 0;
        public string GoodsNumber { get; set; } = "";
        public string ProduceDate { get; set; } = "";
        public string ValidDate { get; set; } = "";
        public string GoodsBTypeID { get; set; } = "";
        public decimal GoodsCostPrice { get; set; } = 0;
        public int HandZeroCost { get; set; } = 0;
        public decimal SaleTotal { get; set; } = 0;
        public decimal Tax { get; set; } = 0;
        public string STypeID { get; set; } = "";
        public decimal TaxMoney { get; set; } = 0;
        public decimal NSalePrice { get; set; } = 0;
        public decimal NSaleTotal { get; set; } = 0;
        public decimal NDiscountPrice { get; set; } = 0;
        public decimal NTotal { get; set; } = 0;
        public decimal NTaxPrice { get; set; } = 0;
        public decimal NTaxTotal { get; set; } = 0;
        public decimal NTaxMoney { get; set; } = 0;
        public int CargoId { get; set; } = 0;
        public int UnitId { get; set; } = 0;
        public int NUnitId { get; set; } = 0;
        public decimal NQty { get; set; } = 0;
        public decimal UnitRate { get; set; } = 0;
        public string NUnitMsg { get; set; } = "";
        public int MUnitId { get; set; } = 0;
        public decimal MQty { get; set; } = 0;
        public decimal MUnitRate { get; set; } = 0;
        public string MUnitMsg { get; set; } = "";
        public decimal MSalePrice { get; set; } = 0;
        public decimal MDiscountPrice { get; set; } = 0;
        public decimal MTaxPrice { get; set; } = 0;
        public decimal CurMSalePrice { get; set; } = 0;
        public decimal CurMDiscountPrice { get; set; } = 0;
        public decimal CurMTaxPrice { get; set; } = 0;
        public int ItemId { get; set; } = 0;
        public int IsCombined { get; set; } = 0;
        public int IsGift { get; set; } = 0;
        public int OldBillNumberID { get; set; } = 0;
        public string OldID { get; set; } = "";
        public decimal CompleteQTY { get; set; } = 0;
        public int PosId { get; set; } = 0;
        public decimal ReferPrice { get; set; } = 0;
        public int PriceStyle { get; set; } = 0;
        public int PromoType { get; set; } = 0;
        public string ETypeID { get; set; } = "";
        public int ShowOrder { get; set; } = 0;
        public string KTypeID { get; set; } = "";
        public string PriceSource { get; set; } = "";
        public string CouponCode { get; set; } = "";
    }
    public class MultAtypeModel
    {

        public int BillNumberID { get; set; }
        public string AtypeId { get; set; }
        public decimal Total { get; set; }
        public string Comment { get; set; }
        public string vipcardid { get; set; }
        public decimal NTotalMoney { get; set; }
        public string TradeNo { get; set; }
        public int PayType { get; set; }
        public int BillType { get; set; }        //单据类型
        public int yhType { get; set; }
        public string CouponCode { get; set; }
        public decimal viptotal { get; set; }
        public string atypecomment { get; set; }

        public MultAtypeModel()
        {
            BillNumberID = 0;
            AtypeId = "";
            Total = 0;
            Comment = "";
            vipcardid = "";
            NTotalMoney = 0;
            PayType = 0;
            yhType = -1;
            TradeNo = "";
            CouponCode = "";
            viptotal = 0;
            atypecomment = "";
        }
    }

    public class Result<T>
    {
        /// <summary>
        /// 获取或设置 Ajax操作结果类型
        /// </summary>
        public AjaxResultType Type { get; set; }

        /// <summary>
        /// 获取或设置 消息内容
        /// </summary>
        public string Content { get; set; }

        /// <summary>
        /// 获取或设置 返回数据
        /// </summary>
        public T Data { get; set; }
        public int TotalRows { get; set; }
    }
    public enum AjaxResultType
    {
        /// <summary>
        /// 消息结果类型
        /// </summary>
        Info = 0,

        /// <summary>
        /// 成功结果类型
        /// </summary>
        Success = 1,

        /// <summary>
        /// 警告结果类型
        /// </summary>
        Warning = 2,

        /// <summary>
        /// 异常结果类型
        /// </summary>
        Error = 3,
        /// <summary>
        /// 失败
        /// </summary>
        Fail = -1
    }

    /// <summary>
    /// DataTable转list
    /// </summary>
    /// <typeparam name="T"></typeparam>
    public class ModelConvertHelper<T> where T : new()
    {
        /// <summary>
        /// 
        /// </summary>
        /// <param name="dt"></param>
        /// <returns></returns>
        public static IList<T> ConvertToModel(DataTable dt)
        {
            // 定义集合    
            IList<T> ts = new List<T>();

            // 获得此模型的类型   
            Type type = typeof(T);
            string tempName = "";

            foreach (DataRow dr in dt.Rows)
            {
                T t = new T();
                // 获得此模型的公共属性      
                PropertyInfo[] propertys = t.GetType().GetProperties();
                foreach (PropertyInfo pi in propertys)
                {
                    tempName = pi.Name;  // 检查DataTable是否包含此列    

                    if (dt.Columns.Contains(tempName))
                    {
                        // 判断此属性是否有Setter      
                        if (!pi.CanWrite) continue;

                        object value = dr[tempName];
                        if (value != DBNull.Value)
                            pi.SetValue(t, value, null);
                    }
                }
                ts.Add(t);
            }
            return ts;
        }
        /// <summary>
        /// 
        /// </summary>
        /// <param name="Sql"></param>
        /// <returns></returns>
        public static IList<T> GetListForSql(string Sql)
        {
            DataTable dts = DbHelperSQL.Query(Sql).Tables[0];
            if (dts != null)
            {
                return ConvertToModel(dts);
            }
            return null;

        }
    }
    public class DisassembleBillModel
    {
        public decimal BillNumberId { get; set; } = 0;

        public string PtypeId { get; set; } = "";
        public decimal Qty { get; set; } = 0;
        public decimal CostPrice { get; set; } = 0;
        public string JobNo { get; set; } = "";
        public decimal Total { get; set; } = 0;

        public string InOrOut { get; set; } = "";
        public DateTime MakeDate { get; set; } = DateTime.Now;
        public string Comment { get; set; } = "";
        public int intisUnitTow { get; set; } = 0;
        public string Serial { get; set; } = "";
        public decimal InputCostPrice { get; set; } = 0;
        public string GoodsNumber { get; set; } = "";
        public string ProduceDate { get; set; } = "";
        public string ValidDate { get; set; } = "";
        public string GoodsBTypeID { get; set; } = "";
        public decimal GoodsCostPrice { get; set; } = 0;
        public int HandZeroCost { get; set; } = 0;

        public string KTypeID { get; set; } = "";
        public string STypeID { get; set; } = "";
        public int CargoId { get; set; } = 0;
        public long ItemId { get; set; } = 0;
        public int IsCombined { get; set; } = 0;
        public decimal nQty { get; set; } = 0;
        public decimal UnitRate { get; set; } = 0;
        public int MUnitId { get; set; } = 0;
        public decimal MUnitRate { get; set; } = 0;
        public decimal MQty { get; set; } = 0;
        public decimal CurMSalePrice { get; set; } = 0;
        public int ShowOrder { get; set; } = 0;
    }


}